Skip to content

Tasdax123/claude-fidelity-translator / plugins/fidelity-translator/skills/fidelity-translator

fidelity-translator

Verified

scripts/project_config.py

View on GitHub
#!/usr/bin/env python3
"""Load and validate `project.yaml` for the fidelity-translator skill.

Search order for project config:
  1. --config <path>           (explicit override)
  2. ./project.yaml            (current working directory)
  3. Walk up ancestors until ~/   looking for project.yaml
  4. ~/.fidelity-translator/defaults.yaml
  5. Built-in defaults below

Example project.yaml — see SKILL.md for the full schema.
"""
import argparse, json, os, sys
from pathlib import Path

try:
    import yaml  # type: ignore
except ImportError:
    yaml = None

DEFAULTS = {
    "project": "untitled",
    "domain": "general",
    "source_language": "auto",
    "target_language": None,
    "glossary": "./glossary.md",
    "output_dir": "./translations/",
    "house_style": "formal-monochrome",
    "model_translation": "opus-4-6",
    "model_critique": "opus-4-6",
    "model_back_translation": "sonnet-4-6",
    "verify_back_translation": "safety-critical-only",
    "hazard_icon": None,
    "disclaimer_template": None,
}

VALID_DOMAINS = {"aerospace", "pharma", "medical-device", "legal",
                 "automotive", "nuclear", "general"}
VALID_STYLES = {"formal-monochrome", "modern", "custom"}
VALID_BT = {"safety-critical-only", "all", "none"}


def find_config(start_dir=None, override=None):
    if override:
        return Path(override).expanduser().resolve()
    cur = Path(start_dir or os.getcwd()).resolve()
    home = Path.home().resolve()
    while True:
        candidate = cur / "project.yaml"
        if candidate.exists():
            return candidate
        if cur == cur.parent or cur == home:
            break
        cur = cur.parent
    fallback = home / ".fidelity-translator" / "defaults.yaml"
    return fallback if fallback.exists() else None


def load(config_path=None):
    cfg = dict(DEFAULTS)
    cfg_file = find_config(override=config_path)
    if cfg_file and yaml is not None:
        try:
            loaded = yaml.safe_load(cfg_file.read_text(encoding="utf-8")) or {}
            cfg.update({k: v for k, v in loaded.items() if v is not None})
            cfg["_loaded_from"] = str(cfg_file)
        except Exception as e:
            sys.stderr.write(f"WARN: could not parse {cfg_file}: {e}\n")
    elif cfg_file:
        sys.stderr.write("WARN: PyYAML not installed; cannot load project.yaml. "
                         "Run `pip install pyyaml`. Using defaults.\n")
    validate(cfg)
    # Resolve relative paths against the project.yaml dir (or cwd if no config)
    base = cfg_file.parent if cfg_file else Path(os.getcwd())
    for key in ("glossary", "output_dir", "hazard_icon", "disclaimer_template"):
        v = cfg.get(key)
        if v and not Path(v).is_absolute():
            cfg[key] = str((base / v).resolve())
    return cfg


def validate(cfg):
    if cfg["domain"] not in VALID_DOMAINS:
        sys.stderr.write(f"WARN: unknown domain '{cfg['domain']}'; using 'general'\n")
        cfg["domain"] = "general"
    if cfg["house_style"] not in VALID_STYLES:
        sys.stderr.write(f"WARN: unknown house_style '{cfg['house_style']}'; using 'formal-monochrome'\n")
        cfg["house_style"] = "formal-monochrome"
    if cfg["verify_back_translation"] not in VALID_BT:
        sys.stderr.write(f"WARN: invalid verify_back_translation; using 'safety-critical-only'\n")
        cfg["verify_back_translation"] = "safety-critical-only"


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--config", default=None)
    ap.add_argument("--json", action="store_true", help="print as JSON")
    args = ap.parse_args()
    cfg = load(args.config)
    if args.json:
        print(json.dumps(cfg, indent=2, ensure_ascii=False))
    else:
        for k, v in cfg.items():
            print(f"{k:30s} {v}")


if __name__ == "__main__":
    main()
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall