slopgate-code-smell-utility-locator
Autoactivate when code-smell hooks or reviews mention feature envy, thin wrappers, duplicate helpers, duplicate code, scattered helpers, builders/factories/config/constants/dataclass reuse, PY-CODE-012, PY-CODE-013, QUALITY-LINT-001, or repeated slopgate code-quality denials. Also load when asked to "find existing helpers", "consolidate utilities", "search for duplicate code", "where is this already implemented", "reuse existing logic", "don't duplicate this", "find similar functions", "utility inventory", "code smell radar", or before adding new helpers/wrappers so agents can find existing shared utilities and consolidate instead of duplicating.
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- slopgate-code-smell-utility-locator
- author
- Slopgate
- license
- MIT
- version
- 1.0.0
- metadata
- { "hermes": { "tags": [ "slopgate", "code-smells", "utilities", "duplication", "constants" ], "related_skills": [ "slopgate-code-hygiene-refactor", "slopgate-intelligent-coding-patterns" ] }, "slopgate": { "rule_ids": [ "PY-CODE-012", "PY-CODE-013", "PY-CODE-009", "PY-CODE-014", "PY-CODE-018", "PY-QUALITY-010", "QUALITY-LINT-001" ], "activation": { "avoid": [ "known package split", "repo-wide lint coordination", "test-only coverage" ], "primary": [ "helper discovery", "constant ownership", "duplicate utilities", "feature envy", "thin wrappers" ] } } }
- description
- Autoactivate when code-smell hooks or reviews mention feature envy, thin wrappers, duplicate helpers, duplicate code, scattered helpers, builders/factories/config/constants/dataclass reuse, PY-CODE-012, PY-CODE-013, QUALITY-LINT-001, or repeated slopgate code-quality denials. Also load when asked to "find existing helpers", "consolidate utilities", "search for duplicate code", "where is this already implemented", "reuse existing logic", "don't duplicate this", "find similar functions", "utility inventory", "code smell radar", or before adding new helpers/wrappers so agents can find existing shared utilities and consolidate instead of duplicating.
- compatibility
- claude-code, opencode, codex, hermes, slopgate
02 资源文件 4
- 脚本scripts/_code_smell_scan.py14.8 KB
- 脚本scripts/code_smell_radar.py6.9 KB
- 脚本scripts/slopgate_code_smell_history.py4.3 KB
- 脚本scripts/utility_inventory.py3.0 KB
03 SKILL.md 正文
Code Smell Utility Locator
Use this skill before writing or retrying code after these smells appear:
- feature envy: logic belongs closer to the object or module it interrogates
- thin wrappers: a function/method only forwards arguments without adding policy, validation, caching, translation, logging, or a real boundary
- duplicate helpers/builders/factories/constants/configs/dataclasses
- repeated slopgate code-quality hook denials, especially
PY-CODE-012,PY-CODE-013,PY-CODE-009,PY-CODE-014,PY-CODE-018, orQUALITY-LINT-001
When to Use
Use before adding helpers, builders, factories, wrappers, constants, config objects, or dataclasses when existing ownership may already exist.
- Rule IDs include
PY-CODE-012,PY-CODE-013,PY-CODE-009,PY-QUALITY-010, or reviews mention feature envy, thin wrappers, duplicate helpers, magic numbers, or repeated literals. - User asks where logic already exists, whether to reuse a helper, or how to consolidate utilities.
- Load this before
slopgate-code-hygiene-refactorwhen the main uncertainty is ownership, not file size.
When Not to Use
Do not use for a known oversized module/package split after ownership is clear; use slopgate-code-hygiene-refactor.
Do not use for broad repo-wide cleanup coordination; use slopgate-hygiene-orchestrator.
Do not use for choosing a design pattern after utility ownership is already settled; use slopgate-intelligent-coding-patterns.
Non-negotiable behavior
- Search before creating a new helper, builder, factory, constants module, config object, dataclass, facade, or wrapper.
- Prefer reusing or moving logic to an existing owner over adding another parallel utility.
- Do not create a wrapper unless it adds a named boundary: validation, normalization, policy, permissions, logging, caching, retries, protocol adaptation, or third-party API shielding.
- For feature envy, first inspect utilities and methods near the envied object/module before extracting a detached helper.
- For duplicate code, consolidate at the closest stable boundary. Do not make a huge generic helper just to silence a smell.
- Use the scripts to produce bounded evidence; do not dump an entire repo into context.
Fast path
From any repository root, run the helper scripts from the skill directory that your harness loaded. Do not assume the Slopgate source checkout path exists.
# If your harness exposes the loaded skill directory, point SKILL_DIR at it.
# Otherwise use the symlinked harness skill path below.
python3 "$SKILL_DIR/scripts/utility_inventory.py" . --format text --limit 160
python3 "$SKILL_DIR/scripts/code_smell_radar.py" . --format text --limit 120
Common harness locations when the bundle manifest has been linked:
# Claude Code
SKILL_DIR="$HOME/.claude/skills/slopgate-code-smell-utility-locator"
# OpenCode
SKILL_DIR="$HOME/.config/opencode/skills/slopgate-code-smell-utility-locator"
# Codex / generic local skill mirror
SKILL_DIR="$HOME/.codex/skills/slopgate-code-smell-utility-locator"
If none of those paths exists, search the active harness skill directory for slopgate-code-smell-utility-locator/SKILL.md and use that parent directory. Keep the search bounded; do not crawl dependency directories.
Script reference
utility_inventory.py
Returns locations and signatures for likely shared utilities:
- helpers/utilities
- builders and factories
- constants
- config/settings classes and modules
- dataclasses / attrs / pydantic-style models
- facades and package re-export surfaces
Examples:
# Whole repo, bounded text output
python3 ~/.local/share/agent-skills/slopgate-code-smell-utility-locator/scripts/utility_inventory.py . --format text --limit 120
# Focus on a package and emit JSON for tooling
python3 ~/.local/share/agent-skills/slopgate-code-smell-utility-locator/scripts/utility_inventory.py src --format json --limit 500
# Narrow by category
python3 ~/.local/share/agent-skills/slopgate-code-smell-utility-locator/scripts/utility_inventory.py . --category builders --category factories
code_smell_radar.py
Returns likely thin wrappers, feature envy candidates, duplicate signatures, duplicate normalized function bodies, and repeated helper names.
Examples:
python3 ~/.local/share/agent-skills/slopgate-code-smell-utility-locator/scripts/code_smell_radar.py . --format text --limit 120
python3 ~/.local/share/agent-skills/slopgate-code-smell-utility-locator/scripts/code_smell_radar.py . --format json --min-duplicate-size 4
Use this output as a map, not as a verdict. The correct fix still depends on architecture.
Slopgate recovery loop
When slopgate fires the same code-smell hook twice on the same path/rule:
- Stop retrying the patch.
- Run
utility_inventory.pyon the nearest package or repository root. - Run
code_smell_radar.pyon the touched package. - Reread the target file and the closest existing utility owner.
- Choose one of these outcomes:
- reuse existing utility;
- move behavior to the envied owner;
- inline the thin wrapper;
- extract a real boundary with named responsibility;
- write a short note explaining why consolidation is unsafe right now.
Output discipline
- Share only the top relevant paths/signatures in the conversation.
- If a script returns hundreds of results, rerun it with a narrower root/category.
- Do not paste raw secrets, environment files, or credential-bearing config. The scripts skip common secret/cache directories, but agents are still responsible for safe output.
04 同仓库更多 Skills
type-strictness
Enforce strict type compliance by eliminating `Any` types and `# type: ignore` comments. Use when: (1) Editing code that contains `Any` as a type annotation (2) Code has `# type: ignore` or `# pyright: ignore` comments (3) User requests type fixes or type strictness enforcement (4) Importing from untyped third-party libraries (5) User asks to "fix types", "remove Any", or "add proper typing" (6) Pyrefly or mypy reports type errors that need resolution (7) Code review reveals weak typing patterns Follows hierarchical resolution: codebase inference → type stubs → library inspection → type guards → casting (last resort).
slopgate-test-extender
Extend Python test suites with parametrization, fixture reuse, and quality enforcement. Use when asked to add tests, extend existing tests, improve test coverage, consolidate duplicate tests, fix test quality issues, or when Slopgate reports untested-production-code, missing test references, or coverage gaps. Triggers on requests like "add tests for X", "extend these tests", "parametrize tests", "consolidate tests", "fix test quality", "improve test coverage", "write tests for this function", "test this module", "behavior tests", "integration tests", "missing tests", "coverage holes", "untested code", or when a hook denies with test-related findings.
slopgate-intelligent-coding-patterns
Pattern-selection playbook for agents editing code with complex branching, stateful parsers/workflows, duplicated skeletons, policy checks, or ordered transforms. Load before refactoring if/elif dispatch chains, boolean-flag state machines, repeated validation predicates, parallel provider/language implementations, or regex/content transformation pipelines. Also load when asked to "apply a design pattern", "which pattern should I use here", "refactor this switch statement", "replace if-elif chain", "state machine pattern", "strategy pattern", "template method", "pipeline pattern", "specification pattern", "dispatch table", "guard clause refactor", "reduce cyclomatic complexity", or when Slopgate fires PY-CODE-014, PY-CODE-017, PY-CODE-018, QUALITY-LINT-001, or PY-QUALITY-010. Use with behavior-locking tests and avoid pattern theater for simple one-off code.
slopgate-hygiene-orchestrator
Orchestrate systematic elimination of linter warnings and errors across Python, TypeScript, and Rust codebases. Use when asked to "clean up lints", "fix all warnings", "run hygiene", "eliminate type errors", "orchestrate code quality fixes", "fix lint errors", "resolve quality gate failures", "pass CI checks", "reduce tech debt", "refactor to pass hooks", or when a Slopgate hook denies with QUALITY-LINT-001, PY-CODE-017, PY-CODE-018, or any collector finding. This skill coordinates multiple code-hygiene-enforcer agents working in parallel on non-conflicting file groupings, tracks progress persistently via JSON exports, and loops until all issues are resolved. CRITICAL: Never run linters directly—always use `slopgate lint check` as the primary gate, discover project-specific tools from config files, and export findings to JSON for tracking.
slopgate-code-smell-utility-locator
Autoactivate when code-smell hooks or reviews mention feature envy, thin wrappers, duplicate helpers, duplicate code, scattered helpers, builders/factories/config/constants/dataclass reuse, PY-CODE-012, PY-CODE-013, QUALITY-LINT-001, or repeated slopgate code-quality denials. Also load when asked to "find existing helpers", "consolidate utilities", "search for duplicate code", "where is this already implemented", "reuse existing logic", "don't duplicate this", "find similar functions", "utility inventory", "code smell radar", or before adding new helpers/wrappers so agents can find existing shared utilities and consolidate instead of duplicating.
slopgate-code-hygiene-refactor
Recovery playbook for Slopgate and project quality failures. Load after hook/lint denials such as PY-CODE-017 flat sibling modules, PY-CODE-018 oversized modules, QUALITY-LINT-001 post-edit quality backstops, PY-QUALITY-010 magic numbers / repeated literals, PY-CODE-012/PY-CODE-013 smell findings, type-suppression bans, duplicate helpers, or repeated hygiene retry loops. Also load when asked to "refactor this module", "split this file", "extract a class", "reduce complexity", "fix god class", "flatten module hierarchy", "move code to a package", "extract helpers", "consolidate duplicates", "replace magic numbers with constants", or when a hook blocks an edit with structural complaints. Focuses on preserving public APIs while refactoring toward packages, cohesive modules, typed seams, and focused tests.