i forgot too commit
All checks were successful
Enterprise AI Code Review / ai-review (pull_request) Successful in 38s

This commit is contained in:
2026-02-01 15:57:45 +01:00
parent 9a334e80be
commit d957120eb3
25 changed files with 5047 additions and 23 deletions

101
cli/config.py Normal file
View File

@@ -0,0 +1,101 @@
"""Configuration management for CLI."""
import json
import os
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any
@dataclass
class CLIConfig:
"""CLI configuration."""
# API settings
api_url: str = "http://127.0.0.1:8080"
auth_token: str | None = None
# User settings
email: str | None = None
allow_emoji: bool = False
# Session settings
default_session: str = "default"
auto_save: bool = True
# Display settings
show_mood: bool = True
show_relationship: bool = False
show_facts: bool = False
show_timestamps: bool = False
# Paths
config_dir: Path = field(default_factory=lambda: Path.home() / ".lc")
sessions_file: Path = field(init=False)
config_file: Path = field(init=False)
def __post_init__(self):
"""Initialize computed fields."""
self.sessions_file = self.config_dir / "sessions.json"
self.config_file = self.config_dir / "config.json"
@classmethod
def load(cls) -> "CLIConfig":
"""Load configuration from file.
Returns:
CLIConfig: Loaded configuration
"""
config = cls()
config.config_dir.mkdir(parents=True, exist_ok=True)
if config.config_file.exists():
try:
with open(config.config_file, "r") as f:
data = json.load(f)
# Update fields from loaded data
for key, value in data.items():
if hasattr(config, key):
setattr(config, key, value)
except (json.JSONDecodeError, IOError) as e:
print(f"Warning: Could not load config: {e}")
return config
def save(self) -> None:
"""Save configuration to file."""
self.config_dir.mkdir(parents=True, exist_ok=True)
data = {
"api_url": self.api_url,
"auth_token": self.auth_token,
"email": self.email,
"allow_emoji": self.allow_emoji,
"default_session": self.default_session,
"auto_save": self.auto_save,
"show_mood": self.show_mood,
"show_relationship": self.show_relationship,
"show_facts": self.show_facts,
"show_timestamps": self.show_timestamps,
}
with open(self.config_file, "w") as f:
json.dump(data, f, indent=2)
def get_api_url(self) -> str:
"""Get API URL, checking environment variables first.
Returns:
str: API URL
"""
return os.getenv("LOYAL_COMPANION_API_URL", self.api_url)
def get_auth_token(self) -> str | None:
"""Get auth token, checking environment variables first.
Returns:
str | None: Auth token or None
"""
return os.getenv("LOYAL_COMPANION_TOKEN", self.auth_token)