- README.MD: add original-source-code and nano-claude-code sections, update overview table (4 subprojects), add v3.0 news entry, expand comparison table with memory/multi-agent/skills dimensions - nano-claude-code v3.0: multi-agent package (multi_agent/), memory package (memory/), skill package (skill/) with built-in /commit and /review skills, context compression (compaction.py), tool registry plugin system, diff view, 17 slash commands, 18 built-in tools, 101 tests (~5000 lines total) - original-source-code/src: add raw TypeScript source tree (1884 files) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
"""Configuration management for nano claude (multi-provider)."""
|
|
import os
|
|
import json
|
|
from pathlib import Path
|
|
|
|
CONFIG_DIR = Path.home() / ".nano_claude"
|
|
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
HISTORY_FILE = CONFIG_DIR / "input_history.txt"
|
|
SESSIONS_DIR = CONFIG_DIR / "sessions"
|
|
|
|
DEFAULTS = {
|
|
"model": "claude-opus-4-6",
|
|
"max_tokens": 8192,
|
|
"permission_mode": "auto", # auto | accept-all | manual
|
|
"verbose": False,
|
|
"thinking": False,
|
|
"thinking_budget": 10000,
|
|
"custom_base_url": "", # for "custom" provider
|
|
"max_tool_output": 32000,
|
|
"max_agent_depth": 3,
|
|
"max_concurrent_agents": 3,
|
|
# Per-provider API keys (optional; env vars take priority)
|
|
# "anthropic_api_key": "sk-ant-..."
|
|
# "openai_api_key": "sk-..."
|
|
# "gemini_api_key": "..."
|
|
# "kimi_api_key": "..."
|
|
# "qwen_api_key": "..."
|
|
# "zhipu_api_key": "..."
|
|
# "deepseek_api_key": "..."
|
|
}
|
|
|
|
|
|
def load_config() -> dict:
|
|
CONFIG_DIR.mkdir(exist_ok=True)
|
|
SESSIONS_DIR.mkdir(exist_ok=True)
|
|
cfg = dict(DEFAULTS)
|
|
if CONFIG_FILE.exists():
|
|
try:
|
|
cfg.update(json.loads(CONFIG_FILE.read_text()))
|
|
except Exception:
|
|
pass
|
|
# Backward-compat: legacy single api_key → anthropic_api_key
|
|
if cfg.get("api_key") and not cfg.get("anthropic_api_key"):
|
|
cfg["anthropic_api_key"] = cfg.pop("api_key")
|
|
# Also accept ANTHROPIC_API_KEY env for backward-compat
|
|
if not cfg.get("anthropic_api_key"):
|
|
cfg["anthropic_api_key"] = os.environ.get("ANTHROPIC_API_KEY", "")
|
|
return cfg
|
|
|
|
|
|
def save_config(cfg: dict):
|
|
CONFIG_DIR.mkdir(exist_ok=True)
|
|
data = dict(cfg)
|
|
CONFIG_FILE.write_text(json.dumps(data, indent=2))
|
|
|
|
|
|
def current_provider(cfg: dict) -> str:
|
|
from providers import detect_provider
|
|
return detect_provider(cfg.get("model", "claude-opus-4-6"))
|
|
|
|
|
|
def has_api_key(cfg: dict) -> bool:
|
|
"""Check whether the active provider has an API key configured."""
|
|
from providers import get_api_key
|
|
pname = current_provider(cfg)
|
|
key = get_api_key(pname, cfg)
|
|
return bool(key)
|
|
|
|
|
|
def calc_cost(model: str, in_tokens: int, out_tokens: int) -> float:
|
|
from providers import calc_cost as _cc
|
|
return _cc(model, in_tokens, out_tokens)
|