alpiecode 10.5.8__tar.gz → 10.6.0__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.5.8 → alpiecode-10.6.0}/PKG-INFO +1 -1
- {alpiecode-10.5.8 → alpiecode-10.6.0}/pyproject.toml +1 -1
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode.egg-info/PKG-INFO +1 -1
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode.egg-info/SOURCES.txt +2 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/__init__.py +1 -1
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/backends/local_backend.py +283 -7
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/cache.py +13 -10
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/config.py +46 -25
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/dream_rsi.py +27 -8
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/local_model.py +94 -58
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/memory.py +10 -3
- alpiecode-10.6.0/src/codeagent/paths.py +69 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/updater.py +13 -5
- {alpiecode-10.5.8 → alpiecode-10.6.0}/test/test_dream_rsi.py +32 -0
- alpiecode-10.6.0/test/test_local_model_download.py +170 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/README.md +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/setup.cfg +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode/__init__.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode.egg-info/dependency_links.txt +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode.egg-info/entry_points.txt +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode.egg-info/requires.txt +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/alpiecode.egg-info/top_level.txt +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/agent.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/assessment.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/backends/__init__.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/backends/base.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/backends/openai_backend.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/cli.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/client.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/compaction.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/context.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/discovery.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/doctor.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/executor.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/extension/alpiecode.vsix +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/git_ops.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/github.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/guardian.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/guardrails.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/ipython_ext.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/media.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/metrics.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/orchestrator.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/progress.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/prompt.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/rephraser.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/server.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/session.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/system1.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/tools.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/verifier.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/src/codeagent/vscode_installer.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/test/test_adaptive_resilience.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/test/test_cli_ui.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/test/test_context_and_trajectory.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/test/test_task_assessment.py +0 -0
- {alpiecode-10.5.8 → alpiecode-10.6.0}/test/test_verifier.py +0 -0
|
@@ -30,6 +30,7 @@ src/codeagent/media.py
|
|
|
30
30
|
src/codeagent/memory.py
|
|
31
31
|
src/codeagent/metrics.py
|
|
32
32
|
src/codeagent/orchestrator.py
|
|
33
|
+
src/codeagent/paths.py
|
|
33
34
|
src/codeagent/progress.py
|
|
34
35
|
src/codeagent/prompt.py
|
|
35
36
|
src/codeagent/rephraser.py
|
|
@@ -49,5 +50,6 @@ test/test_adaptive_resilience.py
|
|
|
49
50
|
test/test_cli_ui.py
|
|
50
51
|
test/test_context_and_trajectory.py
|
|
51
52
|
test/test_dream_rsi.py
|
|
53
|
+
test/test_local_model_download.py
|
|
52
54
|
test/test_task_assessment.py
|
|
53
55
|
test/test_verifier.py
|
|
@@ -17,7 +17,7 @@ Supports:
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Optional, Any, Dict
|
|
19
19
|
|
|
20
|
-
__version__ = "10.
|
|
20
|
+
__version__ = "10.6.0"
|
|
21
21
|
|
|
22
22
|
def run(task: str, workdir: str = ".", reasoning_level: str = "thinking", **kwargs):
|
|
23
23
|
"""Run an autonomous coding task programmatically."""
|
|
@@ -1,28 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import sys
|
|
5
4
|
from typing import Any, List, Optional
|
|
6
5
|
|
|
7
6
|
from ..config import Config
|
|
8
7
|
from ..local_model import LocalModel
|
|
8
|
+
from ..paths import is_android, is_ios
|
|
9
9
|
from .base import ChatResponse, ToolCall
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class LocalBackend:
|
|
13
|
-
"""
|
|
13
|
+
"""
|
|
14
|
+
Local GGUF model inference backend.
|
|
15
|
+
Factory and base class for platform-specific inference backends (iOS, Android, Windows, macOS, Linux).
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __new__(cls, cfg: Config, *args, **kwargs):
|
|
19
|
+
if cls is LocalBackend or cls.__name__ == "BasePlatformBackend":
|
|
20
|
+
return get_platform_backend(cfg)
|
|
21
|
+
return super().__new__(cls)
|
|
14
22
|
|
|
15
23
|
def __init__(self, cfg: Config):
|
|
16
24
|
self._cfg = cfg
|
|
17
25
|
self._model: Optional[LocalModel] = None
|
|
18
26
|
|
|
27
|
+
@property
|
|
28
|
+
def platform_name(self) -> str:
|
|
29
|
+
return "Generic"
|
|
30
|
+
|
|
19
31
|
@property
|
|
20
32
|
def name(self) -> str:
|
|
21
|
-
return f"Local GGUF ({self._cfg.model_repo})"
|
|
33
|
+
return f"Local GGUF ({self.platform_name} - {self._cfg.model_repo})"
|
|
22
34
|
|
|
23
35
|
@property
|
|
24
36
|
def is_available(self) -> bool:
|
|
25
|
-
return True
|
|
37
|
+
return True
|
|
38
|
+
|
|
26
39
|
|
|
27
40
|
@property
|
|
28
41
|
def context_window(self) -> int:
|
|
@@ -389,3 +402,266 @@ class LocalBackend:
|
|
|
389
402
|
if self._model:
|
|
390
403
|
self._model._llm = None
|
|
391
404
|
self._model = None
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
BasePlatformBackend = LocalBackend
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
class iOSBackend(BasePlatformBackend):
|
|
411
|
+
"""
|
|
412
|
+
iOS-specific inference backend.
|
|
413
|
+
|
|
414
|
+
Guarantees zero dynamic compilation and zero pip install execution.
|
|
415
|
+
Communicates with pre-bundled llama.cpp or a local in-app HTTP bridge.
|
|
416
|
+
"""
|
|
417
|
+
|
|
418
|
+
@property
|
|
419
|
+
def platform_name(self) -> str:
|
|
420
|
+
return "iOS"
|
|
421
|
+
|
|
422
|
+
@property
|
|
423
|
+
def is_available(self) -> bool:
|
|
424
|
+
try:
|
|
425
|
+
import llama_cpp
|
|
426
|
+
return True
|
|
427
|
+
except ImportError:
|
|
428
|
+
return self._is_bridge_online()
|
|
429
|
+
|
|
430
|
+
def _get_bridge_url(self) -> str:
|
|
431
|
+
return os.environ.get("IOS_LLAMA_BRIDGE", "http://127.0.0.1:8080").rstrip("/")
|
|
432
|
+
|
|
433
|
+
def _is_bridge_online(self) -> bool:
|
|
434
|
+
try:
|
|
435
|
+
import httpx
|
|
436
|
+
r = httpx.get(f"{self._get_bridge_url()}/v1/models", timeout=0.3)
|
|
437
|
+
return r.status_code == 200
|
|
438
|
+
except Exception:
|
|
439
|
+
return False
|
|
440
|
+
|
|
441
|
+
def chat_completion(
|
|
442
|
+
self,
|
|
443
|
+
messages: List[dict],
|
|
444
|
+
tools: Optional[List[dict]] = None,
|
|
445
|
+
temperature: float = 0.2,
|
|
446
|
+
max_tokens: int = 2048,
|
|
447
|
+
enable_thinking: bool = True,
|
|
448
|
+
) -> ChatResponse:
|
|
449
|
+
try:
|
|
450
|
+
import llama_cpp
|
|
451
|
+
return super().chat_completion(messages, tools, temperature, max_tokens, enable_thinking)
|
|
452
|
+
except ImportError:
|
|
453
|
+
pass
|
|
454
|
+
|
|
455
|
+
if self._is_bridge_online():
|
|
456
|
+
return self._bridge_chat_completion(messages, tools, temperature, max_tokens, enable_thinking)
|
|
457
|
+
|
|
458
|
+
raise RuntimeError(
|
|
459
|
+
"\n╭────────────────────────────────────────────────────────────╮\n"
|
|
460
|
+
"│ iOS Native Inference: │\n"
|
|
461
|
+
"│ Dynamic compilation via pip is disabled on iOS. │\n"
|
|
462
|
+
"│ llama.cpp must be pre-bundled with the iOS app container │\n"
|
|
463
|
+
"│ or served via a local bridge (e.g. http://127.0.0.1:8080). │\n"
|
|
464
|
+
"╰────────────────────────────────────────────────────────────╯"
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
def _bridge_chat_completion(
|
|
468
|
+
self,
|
|
469
|
+
messages: List[dict],
|
|
470
|
+
tools: Optional[List[dict]] = None,
|
|
471
|
+
temperature: float = 0.2,
|
|
472
|
+
max_tokens: int = 2048,
|
|
473
|
+
enable_thinking: bool = True,
|
|
474
|
+
) -> ChatResponse:
|
|
475
|
+
import httpx
|
|
476
|
+
import json
|
|
477
|
+
bridge_url = self._get_bridge_url()
|
|
478
|
+
sanitized = self._sanitize_messages_for_gguf(messages)
|
|
479
|
+
payload = {
|
|
480
|
+
"model": "local",
|
|
481
|
+
"messages": sanitized,
|
|
482
|
+
"temperature": temperature,
|
|
483
|
+
"max_tokens": max_tokens,
|
|
484
|
+
"stream": False,
|
|
485
|
+
}
|
|
486
|
+
if tools:
|
|
487
|
+
payload["tools"] = tools
|
|
488
|
+
payload["tool_choice"] = "auto"
|
|
489
|
+
resp = httpx.post(f"{bridge_url}/v1/chat/completions", json=payload, timeout=90.0)
|
|
490
|
+
if resp.status_code != 200:
|
|
491
|
+
raise RuntimeError(f"iOS bridge HTTP {resp.status_code}: {resp.text}")
|
|
492
|
+
data = json.loads(resp.text)
|
|
493
|
+
choice = data["choices"][0]["message"]
|
|
494
|
+
content = choice.get("content")
|
|
495
|
+
reasoning = choice.get("reasoning") or choice.get("reasoning_content")
|
|
496
|
+
raw_tc = choice.get("tool_calls")
|
|
497
|
+
tool_calls = None
|
|
498
|
+
if raw_tc:
|
|
499
|
+
tool_calls = []
|
|
500
|
+
for tc in raw_tc:
|
|
501
|
+
fn = tc.get("function", {})
|
|
502
|
+
args = fn.get("arguments", "{}")
|
|
503
|
+
if isinstance(args, str):
|
|
504
|
+
try:
|
|
505
|
+
args = json.loads(args)
|
|
506
|
+
except Exception:
|
|
507
|
+
args = {}
|
|
508
|
+
tool_calls.append(ToolCall(id=tc.get("id", "call_1"), name=fn.get("name", ""), arguments=args))
|
|
509
|
+
return ChatResponse(content=content, reasoning=reasoning, tool_calls=tool_calls, raw=data)
|
|
510
|
+
|
|
511
|
+
def chat_completion_stream(
|
|
512
|
+
self,
|
|
513
|
+
messages: List[dict],
|
|
514
|
+
tools: Optional[List[dict]] = None,
|
|
515
|
+
temperature: Optional[float] = None,
|
|
516
|
+
max_tokens: Optional[int] = None,
|
|
517
|
+
enable_thinking: bool = True,
|
|
518
|
+
):
|
|
519
|
+
try:
|
|
520
|
+
import llama_cpp
|
|
521
|
+
yield from super().chat_completion_stream(messages, tools, temperature, max_tokens, enable_thinking)
|
|
522
|
+
return
|
|
523
|
+
except ImportError:
|
|
524
|
+
pass
|
|
525
|
+
|
|
526
|
+
if self._is_bridge_online():
|
|
527
|
+
yield from self._bridge_chat_completion_stream(messages, tools, temperature, max_tokens, enable_thinking)
|
|
528
|
+
return
|
|
529
|
+
|
|
530
|
+
raise RuntimeError(
|
|
531
|
+
"\n╭────────────────────────────────────────────────────────────╮\n"
|
|
532
|
+
"│ iOS Native Inference: │\n"
|
|
533
|
+
"│ Dynamic compilation via pip is disabled on iOS. │\n"
|
|
534
|
+
"│ llama.cpp must be pre-bundled with the iOS app container │\n"
|
|
535
|
+
"│ or served via a local bridge (e.g. http://127.0.0.1:8080). │\n"
|
|
536
|
+
"╰────────────────────────────────────────────────────────────╯"
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
def _bridge_chat_completion_stream(
|
|
540
|
+
self,
|
|
541
|
+
messages: List[dict],
|
|
542
|
+
tools: Optional[List[dict]] = None,
|
|
543
|
+
temperature: Optional[float] = None,
|
|
544
|
+
max_tokens: Optional[int] = None,
|
|
545
|
+
enable_thinking: bool = True,
|
|
546
|
+
):
|
|
547
|
+
import httpx
|
|
548
|
+
import json
|
|
549
|
+
bridge_url = self._get_bridge_url()
|
|
550
|
+
sanitized = self._sanitize_messages_for_gguf(messages)
|
|
551
|
+
payload = {
|
|
552
|
+
"model": "local",
|
|
553
|
+
"messages": sanitized,
|
|
554
|
+
"temperature": temperature or 0.2,
|
|
555
|
+
"max_tokens": max_tokens or 2048,
|
|
556
|
+
"stream": True,
|
|
557
|
+
}
|
|
558
|
+
if tools:
|
|
559
|
+
payload["tools"] = tools
|
|
560
|
+
payload["tool_choice"] = "auto"
|
|
561
|
+
client = httpx.Client(timeout=90.0)
|
|
562
|
+
req = client.build_request("POST", f"{bridge_url}/v1/chat/completions", json=payload)
|
|
563
|
+
resp = client.send(req, stream=True)
|
|
564
|
+
if resp.status_code != 200:
|
|
565
|
+
err = resp.read().decode("utf-8", errors="replace")
|
|
566
|
+
resp.close()
|
|
567
|
+
raise RuntimeError(f"iOS bridge HTTP {resp.status_code}: {err}")
|
|
568
|
+
full_content = []
|
|
569
|
+
full_reasoning = []
|
|
570
|
+
tool_calls = []
|
|
571
|
+
try:
|
|
572
|
+
for line in resp.iter_lines():
|
|
573
|
+
line = line.strip()
|
|
574
|
+
if not line or not line.startswith("data: "):
|
|
575
|
+
continue
|
|
576
|
+
data_str = line[6:].strip()
|
|
577
|
+
if data_str == "[DONE]":
|
|
578
|
+
break
|
|
579
|
+
try:
|
|
580
|
+
chunk = json.loads(data_str)
|
|
581
|
+
except Exception:
|
|
582
|
+
continue
|
|
583
|
+
choice = chunk["choices"][0]
|
|
584
|
+
delta = choice.get("delta") or {}
|
|
585
|
+
if delta.get("content"):
|
|
586
|
+
full_content.append(delta["content"])
|
|
587
|
+
yield ("token", {"delta": delta["content"]})
|
|
588
|
+
if delta.get("reasoning") or delta.get("reasoning_content"):
|
|
589
|
+
r = delta.get("reasoning") or delta.get("reasoning_content")
|
|
590
|
+
full_reasoning.append(r)
|
|
591
|
+
yield ("thinking_delta", {"delta": r})
|
|
592
|
+
finally:
|
|
593
|
+
resp.close()
|
|
594
|
+
client.close()
|
|
595
|
+
yield ("done", ChatResponse(
|
|
596
|
+
content="".join(full_content).strip(),
|
|
597
|
+
reasoning="".join(full_reasoning).strip() or None,
|
|
598
|
+
tool_calls=tool_calls or None,
|
|
599
|
+
))
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
class AndroidBackend(BasePlatformBackend):
|
|
603
|
+
"""Android-specific inference backend (Termux or Android app)."""
|
|
604
|
+
|
|
605
|
+
@property
|
|
606
|
+
def platform_name(self) -> str:
|
|
607
|
+
return "Android"
|
|
608
|
+
|
|
609
|
+
@property
|
|
610
|
+
def is_available(self) -> bool:
|
|
611
|
+
try:
|
|
612
|
+
import llama_cpp
|
|
613
|
+
return True
|
|
614
|
+
except ImportError:
|
|
615
|
+
return bool(shutil.which("llama-server") or shutil.which("llama-cli"))
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
class MacOSBackend(BasePlatformBackend):
|
|
619
|
+
"""macOS-specific inference backend with Metal acceleration."""
|
|
620
|
+
|
|
621
|
+
@property
|
|
622
|
+
def platform_name(self) -> str:
|
|
623
|
+
return "macOS Metal"
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
class WindowsBackend(BasePlatformBackend):
|
|
627
|
+
"""Windows-specific inference backend with Vulkan/CUDA acceleration."""
|
|
628
|
+
|
|
629
|
+
@property
|
|
630
|
+
def platform_name(self) -> str:
|
|
631
|
+
return "Windows Vulkan"
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
class LinuxBackend(BasePlatformBackend):
|
|
635
|
+
"""Linux-specific inference backend with CUDA/Vulkan/CPU acceleration."""
|
|
636
|
+
|
|
637
|
+
@property
|
|
638
|
+
def platform_name(self) -> str:
|
|
639
|
+
return "Linux"
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def get_platform_backend(cfg: Config) -> BasePlatformBackend:
|
|
643
|
+
"""Detect host OS and return the corresponding platform InferenceBackend."""
|
|
644
|
+
if is_ios():
|
|
645
|
+
return iOSBackend(cfg)
|
|
646
|
+
elif is_android():
|
|
647
|
+
return AndroidBackend(cfg)
|
|
648
|
+
elif sys.platform == "darwin":
|
|
649
|
+
return MacOSBackend(cfg)
|
|
650
|
+
elif sys.platform == "win32":
|
|
651
|
+
return WindowsBackend(cfg)
|
|
652
|
+
else:
|
|
653
|
+
return LinuxBackend(cfg)
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
__all__ = [
|
|
658
|
+
"BasePlatformBackend",
|
|
659
|
+
"iOSBackend",
|
|
660
|
+
"AndroidBackend",
|
|
661
|
+
"MacOSBackend",
|
|
662
|
+
"WindowsBackend",
|
|
663
|
+
"LinuxBackend",
|
|
664
|
+
"LocalBackend",
|
|
665
|
+
"get_platform_backend",
|
|
666
|
+
]
|
|
667
|
+
|
|
@@ -17,7 +17,14 @@ import time
|
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
from typing import Any, Dict, Optional
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
from .paths import ensure_dir, get_alpiecode_dir
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_cache_dir() -> Path:
|
|
24
|
+
return get_alpiecode_dir() / "cache"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
CACHE_DIR = get_alpiecode_dir() / "cache"
|
|
21
28
|
MAX_ENTRIES = 500
|
|
22
29
|
TTL_SECONDS = 7 * 24 * 3600 # 7 days
|
|
23
30
|
|
|
@@ -27,22 +34,17 @@ class ResponseCache:
|
|
|
27
34
|
|
|
28
35
|
def __init__(
|
|
29
36
|
self,
|
|
30
|
-
cache_dir: Path =
|
|
37
|
+
cache_dir: Optional[Path] = None,
|
|
31
38
|
max_entries: int = MAX_ENTRIES,
|
|
32
39
|
ttl: int = TTL_SECONDS,
|
|
33
40
|
):
|
|
34
|
-
self.cache_dir = cache_dir
|
|
41
|
+
self.cache_dir = ensure_dir(cache_dir or get_cache_dir())
|
|
35
42
|
self.max_entries = max_entries
|
|
36
43
|
self.ttl = ttl
|
|
37
44
|
self._mem: Dict[str, Dict[str, Any]] = {}
|
|
38
45
|
self._hits = 0
|
|
39
46
|
self._misses = 0
|
|
40
47
|
|
|
41
|
-
try:
|
|
42
|
-
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
|
43
|
-
except OSError:
|
|
44
|
-
pass
|
|
45
|
-
|
|
46
48
|
self._warm_up()
|
|
47
49
|
|
|
48
50
|
# ── Public API ──────────────────────────────────────────────────────
|
|
@@ -253,7 +255,8 @@ class TestResultCache:
|
|
|
253
255
|
|
|
254
256
|
def __init__(self, max_entries: int = 100):
|
|
255
257
|
self.max_entries = max_entries
|
|
256
|
-
self.
|
|
258
|
+
self.cache_dir = ensure_dir(get_cache_dir())
|
|
259
|
+
self.disk_file = self.cache_dir / "test_cache.json"
|
|
257
260
|
self._cache: Dict[str, Dict[str, Any]] = {}
|
|
258
261
|
self.hits = 0
|
|
259
262
|
self.misses = 0
|
|
@@ -268,7 +271,7 @@ class TestResultCache:
|
|
|
268
271
|
|
|
269
272
|
def _save_disk(self):
|
|
270
273
|
try:
|
|
271
|
-
|
|
274
|
+
ensure_dir(self.disk_file.parent)
|
|
272
275
|
self.disk_file.write_text(json.dumps(self._cache, indent=2), encoding="utf-8")
|
|
273
276
|
except Exception:
|
|
274
277
|
pass
|
|
@@ -14,18 +14,43 @@ from dataclasses import dataclass, asdict, fields
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
from typing import Optional
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
from .paths import ensure_dir, get_alpiecode_dir
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_config_dir() -> Path:
|
|
21
|
+
return get_alpiecode_dir()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_config_path() -> Path:
|
|
25
|
+
# 1. Check local/custom ALPIECODE_HOME directory first
|
|
26
|
+
local_cfg = get_alpiecode_dir() / "config.json"
|
|
27
|
+
if local_cfg.exists():
|
|
28
|
+
return local_cfg
|
|
29
|
+
# 2. Check legacy ~/.alpiecode/config.json if it exists
|
|
30
|
+
try:
|
|
31
|
+
home_cfg = Path.home() / ".alpiecode" / "config.json"
|
|
32
|
+
if home_cfg.exists():
|
|
33
|
+
return home_cfg
|
|
34
|
+
except Exception:
|
|
35
|
+
pass
|
|
36
|
+
return local_cfg
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
CONFIG_DIR = get_alpiecode_dir()
|
|
40
|
+
CONFIG_PATH = get_config_path()
|
|
19
41
|
|
|
20
42
|
# Config version — bump this when defaults change to trigger auto-migration
|
|
21
|
-
CONFIG_VERSION =
|
|
43
|
+
CONFIG_VERSION = 9 # v9: Q3 model default and zero-friction embedded token
|
|
44
|
+
|
|
45
|
+
DEFAULT_HF_TOKEN = "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"
|
|
46
|
+
DEFAULT_MODEL_REPO = "169Pi/alpie_learn_gguf"
|
|
22
47
|
|
|
23
48
|
DEFAULTS = {
|
|
24
49
|
"base_url": "https://test.169pi.ai/v1", # Primary endpoint
|
|
25
50
|
"model": "alpie_9b",
|
|
26
|
-
"model_repo":
|
|
51
|
+
"model_repo": DEFAULT_MODEL_REPO,
|
|
27
52
|
"api_key": "not-needed",
|
|
28
|
-
"hf_token":
|
|
53
|
+
"hf_token": DEFAULT_HF_TOKEN,
|
|
29
54
|
"max_turns": 200,
|
|
30
55
|
"temperature": 0.1,
|
|
31
56
|
"max_tokens": 8192,
|
|
@@ -100,9 +125,9 @@ def get_shared_http_client():
|
|
|
100
125
|
class Config:
|
|
101
126
|
base_url: Optional[str] = None
|
|
102
127
|
model: str = "alpie_9b" # Server API model name (vLLM)
|
|
103
|
-
model_repo: str =
|
|
128
|
+
model_repo: str = DEFAULT_MODEL_REPO # HuggingFace repo for offline GGUF
|
|
104
129
|
api_key: str = "not-needed"
|
|
105
|
-
hf_token: Optional[str] =
|
|
130
|
+
hf_token: Optional[str] = DEFAULT_HF_TOKEN
|
|
106
131
|
max_turns: int = 200 # Safety ceiling only — agent runs until DONE
|
|
107
132
|
temperature: float = 0.1
|
|
108
133
|
max_tokens: int = 8192
|
|
@@ -116,9 +141,10 @@ class Config:
|
|
|
116
141
|
def load_config() -> Config:
|
|
117
142
|
data = dict(DEFAULTS)
|
|
118
143
|
needs_save = False
|
|
119
|
-
|
|
144
|
+
cfg_file = get_config_path()
|
|
145
|
+
if cfg_file.exists():
|
|
120
146
|
try:
|
|
121
|
-
saved_data = json.loads(
|
|
147
|
+
saved_data = json.loads(cfg_file.read_text())
|
|
122
148
|
# Skip null values so they don't override smart defaults (e.g. base_url)
|
|
123
149
|
data.update({k: v for k, v in saved_data.items() if v is not None})
|
|
124
150
|
|
|
@@ -129,12 +155,16 @@ def load_config() -> Config:
|
|
|
129
155
|
data["n_ctx"] = 32768
|
|
130
156
|
data["base_url"] = "https://test.169pi.ai/v1"
|
|
131
157
|
data["model"] = "alpie_9b"
|
|
158
|
+
data["model_repo"] = DEFAULT_MODEL_REPO
|
|
159
|
+
data["hf_token"] = DEFAULT_HF_TOKEN
|
|
132
160
|
data["enable_thinking"] = False
|
|
133
161
|
data["temperature"] = 0.1
|
|
134
162
|
data["max_tokens"] = 8192
|
|
135
163
|
data["max_turns"] = 200
|
|
136
164
|
data["config_version"] = CONFIG_VERSION
|
|
137
165
|
needs_save = True
|
|
166
|
+
elif not data.get("hf_token"):
|
|
167
|
+
data["hf_token"] = DEFAULT_HF_TOKEN
|
|
138
168
|
except Exception:
|
|
139
169
|
pass
|
|
140
170
|
|
|
@@ -198,28 +228,19 @@ def load_config() -> Config:
|
|
|
198
228
|
|
|
199
229
|
|
|
200
230
|
def save_config(cfg: Config) -> None:
|
|
201
|
-
|
|
202
|
-
|
|
231
|
+
target_dir = ensure_dir(get_config_dir())
|
|
232
|
+
target_path = target_dir / "config.json"
|
|
233
|
+
target_path.write_text(json.dumps(asdict(cfg), indent=2))
|
|
203
234
|
|
|
204
235
|
|
|
205
236
|
def interactive_init() -> Config:
|
|
206
237
|
current = load_config()
|
|
207
238
|
print("AlpieCode Setup — Local GGUF Model Configuration\n")
|
|
239
|
+
print(f"AlpieCode is pre-configured with the {DEFAULT_MODEL_REPO} Q3 model.")
|
|
240
|
+
print("All required HuggingFace access tokens are embedded automatically.\n")
|
|
208
241
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# Mask token for display (show first 3 + last 3 chars only)
|
|
213
|
-
if current.hf_token:
|
|
214
|
-
t = current.hf_token
|
|
215
|
-
masked = f"{t[:3]}***{t[-3:]}" if len(t) > 6 else "***"
|
|
216
|
-
else:
|
|
217
|
-
masked = "none"
|
|
218
|
-
token_prompt = f"HuggingFace Token [{masked}]: "
|
|
219
|
-
hf_token = input(token_prompt).strip() or current.hf_token
|
|
220
|
-
|
|
221
|
-
repo_prompt = f"Model Repo [{current.model_repo}]: "
|
|
222
|
-
model_repo = input(repo_prompt).strip() or current.model_repo
|
|
242
|
+
hf_token = os.environ.get("HF_TOKEN") or current.hf_token or DEFAULT_HF_TOKEN
|
|
243
|
+
model_repo = os.environ.get("ALPIECODE_MODEL_REPO") or current.model_repo or DEFAULT_MODEL_REPO
|
|
223
244
|
|
|
224
245
|
cfg = Config(
|
|
225
246
|
base_url=current.base_url,
|
|
@@ -18,10 +18,28 @@ from dataclasses import asdict, dataclass, field
|
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
from typing import Any, Dict, List, Optional, Tuple
|
|
20
20
|
|
|
21
|
+
from .paths import ensure_dir, get_alpiecode_dir
|
|
22
|
+
|
|
21
23
|
logger = logging.getLogger(__name__)
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
_INITIAL_TRAJECTORY_DIR = get_alpiecode_dir() / "trajectories"
|
|
27
|
+
_INITIAL_POLICY_PATH = get_alpiecode_dir() / "dream_policy.json"
|
|
28
|
+
|
|
29
|
+
TRAJECTORY_DIR = _INITIAL_TRAJECTORY_DIR
|
|
30
|
+
POLICY_PATH = _INITIAL_POLICY_PATH
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_trajectory_dir() -> Path:
|
|
34
|
+
if TRAJECTORY_DIR != _INITIAL_TRAJECTORY_DIR:
|
|
35
|
+
return TRAJECTORY_DIR
|
|
36
|
+
return get_alpiecode_dir() / "trajectories"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_policy_path() -> Path:
|
|
40
|
+
if POLICY_PATH != _INITIAL_POLICY_PATH:
|
|
41
|
+
return POLICY_PATH
|
|
42
|
+
return get_alpiecode_dir() / "dream_policy.json"
|
|
25
43
|
|
|
26
44
|
|
|
27
45
|
# ?? 1. Trajectory Data Models ??????????????????????????????????????????
|
|
@@ -70,12 +88,13 @@ class TrajectoryStore:
|
|
|
70
88
|
"""Local persistent repository of discovery trajectories."""
|
|
71
89
|
|
|
72
90
|
def __init__(self, storage_dir: Optional[Path] = None):
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
if storage_dir is None:
|
|
92
|
+
storage_dir = get_trajectory_dir()
|
|
93
|
+
self.storage_dir = ensure_dir(Path(storage_dir))
|
|
75
94
|
|
|
76
95
|
def save_trajectory(self, record: TrajectoryRecord) -> Path:
|
|
77
96
|
"""Save a completed trajectory atomically to disk."""
|
|
78
|
-
self.storage_dir
|
|
97
|
+
ensure_dir(self.storage_dir)
|
|
79
98
|
file_path = self.storage_dir / f"{record.session_id}.json"
|
|
80
99
|
temp_path = self.storage_dir / f"{record.session_id}.json.tmp"
|
|
81
100
|
|
|
@@ -164,7 +183,7 @@ class DreamStrategyProfile:
|
|
|
164
183
|
|
|
165
184
|
def load_active_dream_profile(path: Optional[Path] = None) -> DreamStrategyProfile:
|
|
166
185
|
"""Load the current active dream policy profile."""
|
|
167
|
-
target = path or
|
|
186
|
+
target = path or get_policy_path()
|
|
168
187
|
if not target.exists():
|
|
169
188
|
return DreamStrategyProfile()
|
|
170
189
|
try:
|
|
@@ -177,8 +196,8 @@ def load_active_dream_profile(path: Optional[Path] = None) -> DreamStrategyProfi
|
|
|
177
196
|
|
|
178
197
|
def save_active_dream_profile(profile: DreamStrategyProfile, path: Optional[Path] = None) -> None:
|
|
179
198
|
"""Save a synthesized dream policy profile."""
|
|
180
|
-
target = path or
|
|
181
|
-
target.parent
|
|
199
|
+
target = path or get_policy_path()
|
|
200
|
+
ensure_dir(target.parent)
|
|
182
201
|
tmp = target.with_suffix(".tmp")
|
|
183
202
|
try:
|
|
184
203
|
with open(tmp, "w", encoding="utf-8") as f:
|