feat: sparse checkout + shallow fetch для минимального трафика
- git_pull() использует fetch --depth 1 + reset (не качает историю) - sparse checkout: скачивается только latest версия cli.js, не все - Все старые версии остаются в репо, но клиент их не скачивает - README обновлён с git clone --depth 1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,10 +10,13 @@ Patched Claude Code CLI for use with custom API endpoints. Automatic updater inc
|
|||||||
# 1. Install Claude Code (if not installed)
|
# 1. Install Claude Code (if not installed)
|
||||||
npm install -g @anthropic-ai/claude-code
|
npm install -g @anthropic-ai/claude-code
|
||||||
|
|
||||||
# 2. Clone this repo (shallow — downloads only latest version, ~12MB)
|
# 2. Clone this repo (shallow clone — only latest commit, ~12MB)
|
||||||
git clone --depth 1 https://git.sensey24.ru/aibot777/unlimitedcoding.git
|
git clone --depth 1 https://git.sensey24.ru/aibot777/unlimitedcoding.git
|
||||||
cd unlimitedcoding
|
cd unlimitedcoding
|
||||||
|
|
||||||
|
# Note: The updater automatically configures sparse checkout to download
|
||||||
|
# only the latest release, not all historical versions.
|
||||||
|
|
||||||
# 3. Run updater (installs patched cli.js + configures settings)
|
# 3. Run updater (installs patched cli.js + configures settings)
|
||||||
sudo bash uclaude_update.sh
|
sudo bash uclaude_update.sh
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ set -e
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
cd "$SCRIPT_DIR"
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
# Shallow fetch + reset (minimal download — only latest snapshot)
|
# Fetch latest (shallow — only latest commit, minimal download)
|
||||||
git fetch --depth 1 origin master 2>/dev/null && git reset --hard origin/master 2>/dev/null || git pull --quiet 2>/dev/null || true
|
git fetch --depth 1 origin master 2>/dev/null && git reset --hard origin/master 2>/dev/null || git pull --quiet 2>/dev/null || true
|
||||||
|
|
||||||
# Run updater
|
# Run updater
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ def ver_tuple(v):
|
|||||||
def git_pull():
|
def git_pull():
|
||||||
"""Pull latest changes from remote (shallow fetch for minimal download)."""
|
"""Pull latest changes from remote (shallow fetch for minimal download)."""
|
||||||
try:
|
try:
|
||||||
# Shallow fetch + reset — downloads only latest snapshot, not full history
|
# Shallow fetch + reset — downloads only latest commit, not full history
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["git", "fetch", "--depth", "1", "origin", "master"],
|
["git", "fetch", "--depth", "1", "origin", "master"],
|
||||||
cwd=SCRIPT_DIR, capture_output=True, text=True, timeout=60,
|
cwd=SCRIPT_DIR, capture_output=True, text=True, timeout=60,
|
||||||
@@ -170,6 +170,10 @@ def git_pull():
|
|||||||
["git", "reset", "--hard", "origin/master"],
|
["git", "reset", "--hard", "origin/master"],
|
||||||
cwd=SCRIPT_DIR, capture_output=True, text=True, timeout=10,
|
cwd=SCRIPT_DIR, capture_output=True, text=True, timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Setup sparse checkout to download only latest version's cli.js
|
||||||
|
_setup_sparse_checkout()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
eprint(f" {Y}git fetch timed out{D}")
|
eprint(f" {Y}git fetch timed out{D}")
|
||||||
@@ -179,6 +183,50 @@ def git_pull():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_sparse_checkout():
|
||||||
|
"""Configure sparse checkout to only include root files + latest release.
|
||||||
|
|
||||||
|
This avoids downloading cli.js for ALL versions (each ~12MB).
|
||||||
|
Only the latest version's cli.js is checked out.
|
||||||
|
"""
|
||||||
|
index_path = os.path.join(SCRIPT_DIR, "claude", "releases", "index.json")
|
||||||
|
if not os.path.isfile(index_path):
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(index_path, "r") as f:
|
||||||
|
latest = json.load(f).get("latest")
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not latest:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Enable sparse checkout
|
||||||
|
subprocess.run(
|
||||||
|
["git", "config", "core.sparseCheckout", "true"],
|
||||||
|
cwd=SCRIPT_DIR, capture_output=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
sparse_file = os.path.join(SCRIPT_DIR, ".git", "info", "sparse-checkout")
|
||||||
|
os.makedirs(os.path.dirname(sparse_file), exist_ok=True)
|
||||||
|
|
||||||
|
patterns = [
|
||||||
|
"/*", # root files (updater, config, README)
|
||||||
|
"/claude/releases/index.json", # version index
|
||||||
|
f"/claude/releases/v{latest}/", # latest release (cli.js + changelog + install)
|
||||||
|
]
|
||||||
|
|
||||||
|
with open(sparse_file, "w") as f:
|
||||||
|
f.write("\n".join(patterns) + "\n")
|
||||||
|
|
||||||
|
# Apply sparse checkout
|
||||||
|
subprocess.run(
|
||||||
|
["git", "checkout", "HEAD", "--", "."],
|
||||||
|
cwd=SCRIPT_DIR, capture_output=True, timeout=30,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# CLI.js installation
|
# CLI.js installation
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user