Add source code files

This commit is contained in:
2026-02-01 02:55:39 +00:00
parent 83fd1566bc
commit 191d8d54e8

View File

@@ -0,0 +1,38 @@
from dataclasses import field
from pathlib import Path
from typing import List, Optional
import yaml
from pydantic import BaseModel
class Config(BaseModel):
model: str = "codellama"
languages: List[str] = field(default_factory=lambda: ["python", "javascript", "go", "rust"])
severity_threshold: str = "low"
fail_on_critical: bool = False
output_format: str = "text"
ollama_url: str = "http://localhost:11434"
timeout: int = 120
def load_config(config_path: Optional[str] = None) -> Config:
if config_path is None:
config_path_str = str(Path.cwd() / "codeguard.yaml")
else:
config_path_str = config_path
config_file = Path(config_path_str)
if config_file.exists():
with open(config_file) as f:
data = yaml.safe_load(f) or {}
return Config(**data)
return Config()
def save_config(config: Config, config_path: str = "codeguard.yaml") -> None:
config_file = Path(config_path)
with open(config_file, "w") as f:
yaml.dump(config.model_dump(), f)