alpiecode 10.6.0__tar.gz → 10.6.1__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.
- {alpiecode-10.6.0 → alpiecode-10.6.1}/PKG-INFO +1 -1
- {alpiecode-10.6.0 → alpiecode-10.6.1}/pyproject.toml +1 -1
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode.egg-info/PKG-INFO +1 -1
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/__init__.py +1 -1
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/config.py +11 -5
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/local_model.py +12 -4
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/paths.py +46 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_local_model_download.py +68 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/README.md +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/setup.cfg +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode/__init__.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode.egg-info/SOURCES.txt +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode.egg-info/dependency_links.txt +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode.egg-info/entry_points.txt +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode.egg-info/requires.txt +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/alpiecode.egg-info/top_level.txt +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/agent.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/assessment.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/backends/__init__.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/backends/base.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/backends/local_backend.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/backends/openai_backend.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/cache.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/cli.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/client.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/compaction.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/context.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/discovery.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/doctor.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/dream_rsi.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/executor.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/extension/alpiecode.vsix +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/git_ops.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/github.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/guardian.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/guardrails.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/ipython_ext.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/media.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/memory.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/metrics.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/orchestrator.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/progress.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/prompt.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/rephraser.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/server.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/session.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/system1.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/tools.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/updater.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/verifier.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/src/codeagent/vscode_installer.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_adaptive_resilience.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_cli_ui.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_context_and_trajectory.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_dream_rsi.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_task_assessment.py +0 -0
- {alpiecode-10.6.0 → alpiecode-10.6.1}/test/test_verifier.py +0 -0
|
@@ -17,7 +17,7 @@ Supports:
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Optional, Any, Dict
|
|
19
19
|
|
|
20
|
-
__version__ = "10.6.
|
|
20
|
+
__version__ = "10.6.1"
|
|
21
21
|
|
|
22
22
|
def run(task: str, workdir: str = ".", reasoning_level: str = "thinking", **kwargs):
|
|
23
23
|
"""Run an autonomous coding task programmatically."""
|
|
@@ -14,7 +14,10 @@ from dataclasses import dataclass, asdict, fields
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
from typing import Optional
|
|
16
16
|
|
|
17
|
-
from .paths import ensure_dir, get_alpiecode_dir
|
|
17
|
+
from .paths import ensure_dir, get_alpiecode_dir, load_dotenv_if_present
|
|
18
|
+
|
|
19
|
+
# Auto-load .env if present (zero-dependency)
|
|
20
|
+
load_dotenv_if_present()
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
def get_config_dir() -> Path:
|
|
@@ -40,9 +43,10 @@ CONFIG_DIR = get_alpiecode_dir()
|
|
|
40
43
|
CONFIG_PATH = get_config_path()
|
|
41
44
|
|
|
42
45
|
# Config version — bump this when defaults change to trigger auto-migration
|
|
43
|
-
CONFIG_VERSION =
|
|
46
|
+
CONFIG_VERSION = 10 # v10: Secure .env resolution for HF_TOKEN
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
# Read Hugging Face token securely from .env or environment variables
|
|
49
|
+
DEFAULT_HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or ""
|
|
46
50
|
DEFAULT_MODEL_REPO = "169Pi/alpie_learn_gguf"
|
|
47
51
|
|
|
48
52
|
DEFAULTS = {
|
|
@@ -186,6 +190,8 @@ def load_config() -> Config:
|
|
|
186
190
|
data["api_key"] = os.environ[f"{prefix}API_KEY"]
|
|
187
191
|
if os.environ.get("HF_TOKEN"):
|
|
188
192
|
data["hf_token"] = os.environ["HF_TOKEN"]
|
|
193
|
+
elif os.environ.get("HUGGING_FACE_HUB_TOKEN"):
|
|
194
|
+
data["hf_token"] = os.environ["HUGGING_FACE_HUB_TOKEN"]
|
|
189
195
|
|
|
190
196
|
# Context size overrides from environment
|
|
191
197
|
for ctx_var in ("ALPIECODE_N_CTX", "ALPIECODE_CTX_SIZE", "ALPIECODE_CONTEXT_SIZE", "CODEAGENT_N_CTX"):
|
|
@@ -237,9 +243,9 @@ def interactive_init() -> Config:
|
|
|
237
243
|
current = load_config()
|
|
238
244
|
print("AlpieCode Setup — Local GGUF Model Configuration\n")
|
|
239
245
|
print(f"AlpieCode is pre-configured with the {DEFAULT_MODEL_REPO} Q3 model.")
|
|
240
|
-
print("
|
|
246
|
+
print("HuggingFace access tokens are securely read from .env or the HF_TOKEN environment variable.\n")
|
|
241
247
|
|
|
242
|
-
hf_token = os.environ.get("HF_TOKEN") or current.hf_token or DEFAULT_HF_TOKEN
|
|
248
|
+
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or current.hf_token or DEFAULT_HF_TOKEN
|
|
243
249
|
model_repo = os.environ.get("ALPIECODE_MODEL_REPO") or current.model_repo or DEFAULT_MODEL_REPO
|
|
244
250
|
|
|
245
251
|
cfg = Config(
|
|
@@ -12,7 +12,10 @@ import sys
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from typing import Any, Dict, List, Optional
|
|
14
14
|
|
|
15
|
-
from .paths import ensure_dir, get_alpiecode_dir, is_android, is_ios
|
|
15
|
+
from .paths import ensure_dir, get_alpiecode_dir, is_android, is_ios, load_dotenv_if_present
|
|
16
|
+
|
|
17
|
+
# Auto-load .env if present (zero-dependency)
|
|
18
|
+
load_dotenv_if_present()
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
def get_model_cache_dir() -> Path:
|
|
@@ -20,7 +23,7 @@ def get_model_cache_dir() -> Path:
|
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
CACHE_DIR = get_alpiecode_dir() / "models"
|
|
23
|
-
DEFAULT_HF_TOKEN = "
|
|
26
|
+
DEFAULT_HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or ""
|
|
24
27
|
DEFAULT_REPO = "169Pi/alpie_learn_gguf"
|
|
25
28
|
DEFAULT_CTX_SIZE = 32768 # 32k tokens default for fast loading (supports up to 256k)
|
|
26
29
|
|
|
@@ -126,7 +129,8 @@ def download_model(repo_id: str = DEFAULT_REPO, token: Optional[str] = None) ->
|
|
|
126
129
|
OFFLINE-FIRST: Checks local cache for BOTH text and vision models before network calls.
|
|
127
130
|
"""
|
|
128
131
|
cache_dir = ensure_dir(get_model_cache_dir())
|
|
129
|
-
|
|
132
|
+
raw_token = token or os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") or DEFAULT_HF_TOKEN
|
|
133
|
+
hf_token = raw_token.strip() if (isinstance(raw_token, str) and raw_token.strip()) else None
|
|
130
134
|
|
|
131
135
|
# ── STEP 1: Check local cache FIRST (zero network) ───────────────
|
|
132
136
|
local_ggufs = list(cache_dir.glob("*.gguf"))
|
|
@@ -159,7 +163,11 @@ def download_model(repo_id: str = DEFAULT_REPO, token: Optional[str] = None) ->
|
|
|
159
163
|
if "401" in err_str or "unauthorized" in err_str:
|
|
160
164
|
raise RuntimeError(
|
|
161
165
|
f"\n❌ HuggingFace Authentication Failed for '{repo_id}'.\n"
|
|
162
|
-
"
|
|
166
|
+
" The repository is private or requires authentication.\n"
|
|
167
|
+
" Please provide a HuggingFace token via:\n"
|
|
168
|
+
" 1. A .env file in your working directory: HF_TOKEN=your_token\n"
|
|
169
|
+
" 2. Environment variable: export HF_TOKEN=your_token\n"
|
|
170
|
+
" 3. Or make the HuggingFace repository Public."
|
|
163
171
|
) from e
|
|
164
172
|
elif "403" in err_str or "forbidden" in err_str or "storage limit" in err_str:
|
|
165
173
|
raise RuntimeError(
|
|
@@ -67,3 +67,49 @@ def is_android() -> bool:
|
|
|
67
67
|
return True
|
|
68
68
|
return os.environ.get("ALPIECODE_PLATFORM", "").lower() == "android"
|
|
69
69
|
|
|
70
|
+
|
|
71
|
+
def load_dotenv_if_present(dotenv_path: Optional[Path] = None) -> None:
|
|
72
|
+
"""
|
|
73
|
+
Lightweight, pure-Python .env file loader (zero external dependencies).
|
|
74
|
+
Loads variables into os.environ without overwriting existing environment variables.
|
|
75
|
+
Checks:
|
|
76
|
+
1. Explicit dotenv_path (if provided)
|
|
77
|
+
2. Path.cwd() / ".env"
|
|
78
|
+
3. get_alpiecode_dir() / ".env"
|
|
79
|
+
4. Path.home() / ".alpiecode" / ".env" (fallback)
|
|
80
|
+
"""
|
|
81
|
+
candidates = []
|
|
82
|
+
if dotenv_path:
|
|
83
|
+
candidates.append(Path(dotenv_path))
|
|
84
|
+
else:
|
|
85
|
+
candidates.append(Path.cwd() / ".env")
|
|
86
|
+
candidates.append(get_alpiecode_dir() / ".env")
|
|
87
|
+
try:
|
|
88
|
+
candidates.append(Path.home() / ".alpiecode" / ".env")
|
|
89
|
+
except Exception:
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
for candidate in candidates:
|
|
93
|
+
if candidate.is_file():
|
|
94
|
+
try:
|
|
95
|
+
with open(candidate, "r", encoding="utf-8") as f:
|
|
96
|
+
for line in f:
|
|
97
|
+
line = line.strip()
|
|
98
|
+
if not line or line.startswith("#"):
|
|
99
|
+
continue
|
|
100
|
+
if line.startswith("export "):
|
|
101
|
+
line = line[7:].strip()
|
|
102
|
+
if "=" in line:
|
|
103
|
+
key, val = line.split("=", 1)
|
|
104
|
+
key = key.strip()
|
|
105
|
+
val = val.strip()
|
|
106
|
+
if len(val) >= 2 and (
|
|
107
|
+
(val.startswith('"') and val.endswith('"'))
|
|
108
|
+
or (val.startswith("'") and val.endswith("'"))
|
|
109
|
+
):
|
|
110
|
+
val = val[1:-1]
|
|
111
|
+
if key and key not in os.environ:
|
|
112
|
+
os.environ[key] = val
|
|
113
|
+
except Exception:
|
|
114
|
+
pass
|
|
115
|
+
|
|
@@ -168,3 +168,71 @@ def test_ios_backend_with_bridge():
|
|
|
168
168
|
res = b.chat_completion([{"role": "user", "content": "hello"}])
|
|
169
169
|
assert res.content == "response from in-app bridge"
|
|
170
170
|
|
|
171
|
+
|
|
172
|
+
def test_load_dotenv_custom_path(monkeypatch, tmp_path):
|
|
173
|
+
"""Test pure-Python .env parsing with exports, comments, quotes, and existing vars."""
|
|
174
|
+
from codeagent.paths import load_dotenv_if_present
|
|
175
|
+
import os
|
|
176
|
+
|
|
177
|
+
env_file = tmp_path / ".env"
|
|
178
|
+
env_file.write_text(
|
|
179
|
+
"# Comment line\n"
|
|
180
|
+
"TEST_VAR_A=hello_world\n"
|
|
181
|
+
"export TEST_VAR_B=\"quoted_value\"\n"
|
|
182
|
+
"TEST_VAR_C='single_quoted'\n"
|
|
183
|
+
"EXISTING_VAR=new_value\n"
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
monkeypatch.setenv("EXISTING_VAR", "original_value")
|
|
187
|
+
monkeypatch.delenv("TEST_VAR_A", raising=False)
|
|
188
|
+
monkeypatch.delenv("TEST_VAR_B", raising=False)
|
|
189
|
+
monkeypatch.delenv("TEST_VAR_C", raising=False)
|
|
190
|
+
|
|
191
|
+
load_dotenv_if_present(dotenv_path=env_file)
|
|
192
|
+
|
|
193
|
+
assert os.environ.get("TEST_VAR_A") == "hello_world"
|
|
194
|
+
assert os.environ.get("TEST_VAR_B") == "quoted_value"
|
|
195
|
+
assert os.environ.get("TEST_VAR_C") == "single_quoted"
|
|
196
|
+
assert os.environ.get("EXISTING_VAR") == "original_value" # Preserved
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def test_download_model_anonymous_token(monkeypatch):
|
|
200
|
+
"""When no HF_TOKEN is configured, download_model passes token=None for public access."""
|
|
201
|
+
monkeypatch.delenv("HF_TOKEN", raising=False)
|
|
202
|
+
monkeypatch.delenv("HUGGING_FACE_HUB_TOKEN", raising=False)
|
|
203
|
+
|
|
204
|
+
with tempfile.TemporaryDirectory() as td:
|
|
205
|
+
cache_dir = Path(td)
|
|
206
|
+
captured_tokens = []
|
|
207
|
+
|
|
208
|
+
def mock_list_files(repo_id, token):
|
|
209
|
+
captured_tokens.append(token)
|
|
210
|
+
return ["alpie-vl-text-q3_k_m.gguf", "alpie-vl-mmproj-f16.gguf"]
|
|
211
|
+
|
|
212
|
+
def mock_download(repo_id, filename, local_dir, token):
|
|
213
|
+
captured_tokens.append(token)
|
|
214
|
+
(local_dir / filename).touch()
|
|
215
|
+
|
|
216
|
+
with patch("codeagent.local_model.get_model_cache_dir", return_value=cache_dir), \
|
|
217
|
+
patch("codeagent.local_model.DEFAULT_HF_TOKEN", ""), \
|
|
218
|
+
patch("huggingface_hub.list_repo_files", side_effect=mock_list_files), \
|
|
219
|
+
patch("huggingface_hub.hf_hub_download", side_effect=mock_download):
|
|
220
|
+
download_model(token=None)
|
|
221
|
+
assert None in captured_tokens
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def test_download_model_401_error_guidance(monkeypatch):
|
|
225
|
+
"""When a 401 Unauthorized occurs, AlpieCode gives clear guidance on .env and public repos."""
|
|
226
|
+
with tempfile.TemporaryDirectory() as td:
|
|
227
|
+
cache_dir = Path(td)
|
|
228
|
+
|
|
229
|
+
with patch("codeagent.local_model.get_model_cache_dir", return_value=cache_dir), \
|
|
230
|
+
patch("huggingface_hub.list_repo_files", side_effect=Exception("401 Client Error: Unauthorized for url")):
|
|
231
|
+
with pytest.raises(RuntimeError) as exc_info:
|
|
232
|
+
download_model()
|
|
233
|
+
err_msg = str(exc_info.value)
|
|
234
|
+
assert "HuggingFace Authentication Failed" in err_msg
|
|
235
|
+
assert ".env file" in err_msg
|
|
236
|
+
assert "HF_TOKEN" in err_msg
|
|
237
|
+
assert "make the HuggingFace repository Public" in err_msg
|
|
238
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|