feat: migrate config to pydantic-settings (#65)

This commit is contained in:
banteg
2026-01-08 11:20:10 +04:00
committed by GitHub
parent 26df1c8ac0
commit d606833603
18 changed files with 937 additions and 131 deletions
+2 -1
View File
@@ -274,7 +274,8 @@ flowchart LR
subgraph toml_contents["takopi.toml"]
direction TB
global["bot_token<br/>chat_id<br/>default_engine"]
global["transport<br/>default_engine"]
telegram_cfg["[transports.telegram]<br/>bot_token = ...<br/>chat_id = ..."]
claude_cfg["[claude]<br/>model = ..."]
codex_cfg["[codex]<br/>model = ..."]
projects_cfg["[projects.alias]<br/>path = ...<br/>worktrees_dir = ...<br/>default_engine = ..."]
+10 -3
View File
@@ -229,11 +229,18 @@ Self-documenting msgspec schemas for decoding engine JSONL streams.
class ConfigError(RuntimeError): ...
```
### `telegram/config.py` - Configuration loading
### `settings.py` - Settings loading
```python
def load_telegram_config() -> tuple[dict, Path]:
# Loads ~/.takopi/takopi.toml
def load_settings(path: str | Path | None = None) -> tuple[TakopiSettings, Path]:
# Loads ~/.takopi/takopi.toml (TOML + env), validates via pydantic-settings
```
### `config_store.py` - Raw TOML read/write
```python
def read_raw_toml(path: Path) -> dict:
# Loads TOML for merge/update without clobbering extra sections
```
### `logging.py` - Secure logging setup
+3
View File
@@ -20,6 +20,9 @@ All config lives in `~/.takopi/takopi.toml`.
```toml
default_engine = "codex" # optional
default_project = "z80" # optional
transport = "telegram" # required
[transports.telegram]
bot_token = "..." # required
chat_id = 123 # required