chore: 移除 resolve_key() 等 skill 端函数,更新 CLAUDE.md 配置描述

This commit is contained in:
Zhengshou Lai
2026-07-06 21:18:04 +08:00
parent 321dc57e30
commit 958a9f2f01
2 changed files with 1 additions and 54 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ mytoolkit env list # 查看所有 key
mytoolkit env export # 导出为 shell export 语句
```
API key 读取顺序(所有 skill 脚本统一):环境变量 → `~/.mytoolkit/config.json`。共享调用为 `mytoolkit.config.resolve_key()`
本文件仅管理 mytoolkit 自身配置。Skill 脚本各自由其自身管理 API key(读取 `~/.xiaohe/agent/config.json`),与本配置独立
## 3. 语音合成 (TTS)
-53
View File
@@ -126,56 +126,3 @@ class Config:
# Global singleton
config = Config()
# ------------------------------------------------------------------
# Shared utility: 2-layer key resolution for skill scripts
# ------------------------------------------------------------------
def resolve_key(name: str) -> str:
"""Two-layer key resolution.
Priority:
1. Environment variable (checks ``MYCLI_<NAME>`` first, then ``<NAME>``)
2. ``~/.mytoolkit/config.json`` → ``keys.<name>``
Returns the key value, or ``""`` if not found.
"""
# 1. Env var (MYCLI_ prefix first, then bare)
env_name = name.upper()
for var in (f"MYCLI_{env_name}", env_name):
val = os.environ.get(var, "")
if val:
return val
# 2. ~/.mytoolkit/config.json
try:
cfg_path = Path.home() / ".mytoolkit" / "config.json"
if cfg_path.exists():
data = json.loads(cfg_path.read_text())
return data.get("keys", {}).get(name, "")
except (json.JSONDecodeError, OSError):
pass
return ""
def write_key_to_mytoolkit(name: str, value: str) -> None:
"""Write a key into ~/.mytoolkit/config.json (persistent).
Called by skills when a key is missing and the user provides it.
"""
cfg_path = Path.home() / ".mytoolkit" / "config.json"
cfg_path.parent.mkdir(parents=True, exist_ok=True)
try:
if cfg_path.exists():
data = json.loads(cfg_path.read_text())
else:
data = {}
if "keys" not in data:
data["keys"] = {}
data["keys"][name] = value
cfg_path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
except (json.JSONDecodeError, OSError):
data = {"keys": {name: value}}
cfg_path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n")