Skip to content

JordanGunn/nunchuck / skills/sniff/sniff-couplers

sniff-couplers

Verified

Detect couplers smells (Message Chains, Feature Envy) using deterministic heuristics and append findings to `.sniff/findings.jsonl`.

scripts/include/sniff_scan_cli.py

View on GitHub
from __future__ import annotations

import argparse
import subprocess
import sys
from pathlib import Path
from typing import Any


def _repo_root() -> Path:
    proc = subprocess.run(
        ["git", "rev-parse", "--show-toplevel"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        check=False,
    )
    if proc.returncode == 0:
        p = proc.stdout.decode("utf-8", errors="replace").strip()
        if p:
            return Path(p)
    return Path.cwd()

def _parse_thresholds(items: list[str] | None) -> dict[str, Any]:
    out: dict[str, Any] = {}
    if not items:
        return out
    for it in items:
        if "=" not in it:
            continue
        k, v = it.split("=", 1)
        k = k.strip()
        v = v.strip()
        if not k:
            continue
        try:
            out[k] = int(v)
        except Exception:
            out[k] = v
    return out


def cmd_help() -> int:
    print("sniff-couplers commands:")
    print("  help")
    print("  validate")
    print("  scan [--threshold k=v]...")
    print("  clean")
    return 0


def cmd_validate() -> int:
    repo_root = _repo_root()
    local = Path(__file__).resolve().parent
    if not (local / "sniff_scan.py").exists():
        print(f"error: missing implementation at {local}", file=sys.stderr)
        return 1
    if not (repo_root / ".git").exists():
        print("error: not a git repository (missing .git)", file=sys.stderr)
        return 1

    print("ok: sniff-couplers cli is runnable")
    return 0


def cmd_scan(args: argparse.Namespace) -> int:
    repo_root = _repo_root()
    from sniff_scan import scan_group

    thresholds = _parse_thresholds(args.threshold)
    n = scan_group(repo_root, "couplers", thresholds=thresholds)
    print(f"ok: appended {n} new finding(s)")
    return 0


def cmd_clean() -> int:
    repo_root = _repo_root()
    sniff_dir = repo_root / ".sniff"
    for p in [sniff_dir / "index.json", sniff_dir / "state.json"]:
        try:
            if p.exists():
                p.unlink()
        except Exception:
            pass
    cache = sniff_dir / "cache"
    if cache.exists() and cache.is_dir():
        for child in sorted(cache.rglob("*"), reverse=True):
            try:
                if child.is_file():
                    child.unlink()
                elif child.is_dir():
                    child.rmdir()
            except Exception:
                pass
        try:
            cache.rmdir()
        except Exception:
            pass
    print("ok: cleaned derived .sniff artifacts (index/state/cache)")
    return 0


def main(argv: list[str]) -> int:
    parser = argparse.ArgumentParser(add_help=False)
    sub = parser.add_subparsers(dest="cmd")

    sub.add_parser("help")
    sub.add_parser("validate")

    p_scan = sub.add_parser("scan")
    p_scan.add_argument("--threshold", action="append", default=[], help="override threshold, e.g. message_chain_depth=5")

    sub.add_parser("clean")

    ns = parser.parse_args(argv[1:] if len(argv) > 1 else [])
    cmd = ns.cmd or "help"

    if cmd == "help":
        return cmd_help()
    if cmd == "validate":
        return cmd_validate()
    if cmd == "scan":
        return cmd_scan(ns)
    if cmd == "clean":
        return cmd_clean()

    print(f"error: unknown command '{cmd}'", file=sys.stderr)
    return 1


if __name__ == "__main__":
    raise SystemExit(main(sys.argv))
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