bharatcode 0.1.0__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.
- bharatcode/__init__.py +13 -0
- bharatcode/agent.py +2088 -0
- bharatcode/commands.py +1072 -0
- bharatcode/config.py +93 -0
- bharatcode/coordinator.py +670 -0
- bharatcode/cost.py +77 -0
- bharatcode/diff.py +113 -0
- bharatcode/hooks.py +75 -0
- bharatcode/index.py +155 -0
- bharatcode/main.py +846 -0
- bharatcode/memory.py +286 -0
- bharatcode/permissions.py +99 -0
- bharatcode/project.py +179 -0
- bharatcode/session_storage.py +108 -0
- bharatcode/skills.py +1746 -0
- bharatcode/subagent.py +363 -0
- bharatcode/tools.py +1021 -0
- bharatcode/ui.py +72 -0
- bharatcode-0.1.0.dist-info/METADATA +150 -0
- bharatcode-0.1.0.dist-info/RECORD +23 -0
- bharatcode-0.1.0.dist-info/WHEEL +5 -0
- bharatcode-0.1.0.dist-info/entry_points.txt +3 -0
- bharatcode-0.1.0.dist-info/top_level.txt +1 -0
bharatcode/config.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Config system — reads BHARATCODE.md from project root (like CLAUDE.md).
|
|
3
|
+
Also manages API keys and user settings.
|
|
4
|
+
"""
|
|
5
|
+
import os
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from dotenv import load_dotenv
|
|
9
|
+
|
|
10
|
+
load_dotenv()
|
|
11
|
+
|
|
12
|
+
CONFIG_DIR = Path.home() / ".bharatcode"
|
|
13
|
+
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
14
|
+
LOG_FILE = CONFIG_DIR / "tool_log.txt"
|
|
15
|
+
|
|
16
|
+
# Maps user-facing Sylithe names → real DeepSeek API model IDs
|
|
17
|
+
MODEL_API_MAP = {
|
|
18
|
+
"sylithe-flash": "deepseek-v4-flash",
|
|
19
|
+
"sylithe-pro": "deepseek-v4-pro",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# Model aliases — old names redirect transparently (no-op if already API names)
|
|
23
|
+
MODEL_ALIASES = {
|
|
24
|
+
"deepseek-chat": "deepseek-v4-flash",
|
|
25
|
+
"deepseek-reasoner": "deepseek-v4-pro",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
DEFAULTS = {
|
|
29
|
+
"api_key": "",
|
|
30
|
+
"model": "deepseek-v4-flash",
|
|
31
|
+
"max_iterations": 100,
|
|
32
|
+
"show_tool_calls": True,
|
|
33
|
+
"auto_approve": False,
|
|
34
|
+
"auto_checkpoint": True, # git-commit changes after each successful turn
|
|
35
|
+
"theme": "dark",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def load_config() -> dict:
|
|
39
|
+
CONFIG_DIR.mkdir(exist_ok=True)
|
|
40
|
+
cfg = dict(DEFAULTS)
|
|
41
|
+
if CONFIG_FILE.exists():
|
|
42
|
+
with open(CONFIG_FILE) as f:
|
|
43
|
+
cfg.update(json.load(f))
|
|
44
|
+
env_key = os.getenv("DEEPSEEK_API_KEY") or os.getenv("BHARATCODE_API_KEY")
|
|
45
|
+
if env_key:
|
|
46
|
+
cfg["api_key"] = env_key
|
|
47
|
+
# Silently migrate old model names to new ones
|
|
48
|
+
cfg["model"] = MODEL_ALIASES.get(cfg.get("model", ""), cfg.get("model", DEFAULTS["model"]))
|
|
49
|
+
return cfg
|
|
50
|
+
|
|
51
|
+
def save_config(cfg: dict):
|
|
52
|
+
CONFIG_DIR.mkdir(exist_ok=True)
|
|
53
|
+
with open(CONFIG_FILE, "w") as f:
|
|
54
|
+
json.dump(cfg, f, indent=2)
|
|
55
|
+
|
|
56
|
+
def get_api_key() -> str:
|
|
57
|
+
key = load_config().get("api_key") or os.getenv("DEEPSEEK_API_KEY")
|
|
58
|
+
if not key:
|
|
59
|
+
raise ValueError(
|
|
60
|
+
"No API key found.\n"
|
|
61
|
+
"Run: bharatcode config --key YOUR_DEEPSEEK_KEY\n"
|
|
62
|
+
"Or set: DEEPSEEK_API_KEY=... in your environment"
|
|
63
|
+
)
|
|
64
|
+
return key
|
|
65
|
+
|
|
66
|
+
def model_label(model: str) -> str:
|
|
67
|
+
"""User-facing display name for a model ID."""
|
|
68
|
+
return {"deepseek-v4-flash": "Sylithe Code Flash", "deepseek-v4-pro": "Sylithe Code Pro"}.get(model, model)
|
|
69
|
+
|
|
70
|
+
def load_project_instructions(cwd: str = ".") -> str:
|
|
71
|
+
"""Walk up from cwd looking for BHARATCODE.md — like Claude Code's CLAUDE.md walk.
|
|
72
|
+
Parent-directory files are included first; child directory overrides take precedence."""
|
|
73
|
+
found: list[str] = []
|
|
74
|
+
current = Path(cwd).resolve()
|
|
75
|
+
visited: set[Path] = set()
|
|
76
|
+
while current not in visited:
|
|
77
|
+
visited.add(current)
|
|
78
|
+
for name in ("BHARATCODE.md", ".bharatcode.md"):
|
|
79
|
+
p = current / name
|
|
80
|
+
if p.exists():
|
|
81
|
+
try:
|
|
82
|
+
found.append(
|
|
83
|
+
f"\n\n--- Project Instructions ({p}) ---\n"
|
|
84
|
+
+ p.read_text(encoding="utf-8")
|
|
85
|
+
)
|
|
86
|
+
except Exception:
|
|
87
|
+
pass
|
|
88
|
+
parent = current.parent
|
|
89
|
+
if parent == current: # filesystem root
|
|
90
|
+
break
|
|
91
|
+
current = parent
|
|
92
|
+
# Reverse so parent-dir instructions appear first, child dir last (highest priority)
|
|
93
|
+
return "".join(reversed(found))
|