AgentSkillsCN

code-sentinel

当代码模式测试失败时使用——修复反复出现的反模式,并记录其根本原因和验证

SKILL.md
--- frontmatter
name: code-sentinel
description: Use when code pattern tests fail - fixes recurring anti-patterns with documented root causes and verification

Code Sentinel

Fix recurring anti-patterns detected by automated code pattern tests.

You MUST use this skill when code pattern tests fail. Even if the fix looks obvious. The anti-pattern files document WHY patterns fail, not just HOW to fix them.

Workflow

  1. Run your project's code pattern tests (e.g., pytest tests/test_code_patterns.py -v)
  2. For each failing test, read the anti-pattern file (see index below)
  3. Understand the root cause (not just the fix)
  4. Apply the documented fix
  5. Verify tests pass

Anti-Pattern Index

CI/Workflow Anti-Patterns

Issues that occur in GitHub Actions workflows and CI pipelines.

Anti-PatternFileAutomated Test
Heredocs fail inside YAML run: blocksci-workflow/yaml-heredoc-indentation.mdtest_no_heredocs_in_github_actions
grep -c || echo "0" creates duplicate outputci-workflow/grep-exit-code-echo-fallback.mdtest_no_grep_exit_code_echo_pattern
Git pull/rebase fails with dirty working treeci-workflow/git-pull-without-autostash.mdtest_git_operations_with_staging
gh workflow run silently fails without permissionci-workflow/gh-workflow-run-permissions.mdtest_workflow_dispatch_has_actions_permission
Windows venv path used on Linux runnerci-workflow/windows-venv-path-on-linux.mdtest_venv_activation_uses_linux_path

Build/Packaging Anti-Patterns

Issues with PyInstaller bundling, version generation, and cross-platform builds.

Anti-PatternFileAutomated Test
Missing hidden imports after refactoringbuild-packaging/pyinstaller-missing-hidden-imports.mdtest_pyinstaller_hidden_imports
Import path case mismatch breaks bundlingbuild-packaging/import-path-case-mismatch.md(manual)
Bare imports for sibling modules fail in bundlebuild-packaging/sibling-absolute-import-bundling.mdtest_sibling_imports_use_relative_syntax
Gitignored file committed before rulebuild-packaging/gitignored-file-still-tracked.md(manual)
Version hash embedded before commitbuild-packaging/version-hash-before-commit.md(design issue)
Windows backslash paths in .spec filebuild-packaging/windows-backslash-in-spec.mdtest_spec_uses_forward_slashes

Application/Runtime Anti-Patterns

Issues in application code that cause runtime failures or unexpected behavior.

Anti-PatternFileAutomated Test
Sort without secondary tiebreaker keyapplication-runtime/sort-without-tiebreaker.mdtest_deterministic_file_sorting
Fixed window geometry cuts off contentapplication-runtime/fixed-window-geometry.mdtest_no_fixed_window_geometry
Same constant defined in multiple modulesapplication-runtime/duplicate-module-level-constants.md(manual)
Optional import fails silentlyapplication-runtime/silent-optional-import-failure.md(manual)
PIL ImageGrab black on secondary monitorapplication-runtime/pil-imagegrab-multimonitor.md(hardware-dependent)
PIL-saved ICO renders invisibleapplication-runtime/pil-ico-save-invisible.md(Windows-dependent)

Quick Reference: Test-to-File Mapping

code
test_no_heredocs_in_github_actions       → ci-workflow/yaml-heredoc-indentation.md
test_no_grep_exit_code_echo_pattern      → ci-workflow/grep-exit-code-echo-fallback.md
test_git_operations_with_staging         → ci-workflow/git-pull-without-autostash.md
test_workflow_dispatch_has_actions_permission → ci-workflow/gh-workflow-run-permissions.md
test_venv_activation_uses_linux_path     → ci-workflow/windows-venv-path-on-linux.md
test_pyinstaller_hidden_imports          → build-packaging/pyinstaller-missing-hidden-imports.md
test_sibling_imports_use_relative_syntax → build-packaging/sibling-absolute-import-bundling.md
test_spec_uses_forward_slashes           → build-packaging/windows-backslash-in-spec.md
test_deterministic_file_sorting          → application-runtime/sort-without-tiebreaker.md
test_no_fixed_window_geometry            → application-runtime/fixed-window-geometry.md

Common Mistakes

MistakeWhy It's Wrong
"Fix is obvious, skip the skill"You miss the root cause. Next time you'll make the same mistake.
Fixing without reading anti-pattern docThe doc explains WHY, not just WHAT. Understanding prevents recurrence.
Not verifying tests passThe pattern might exist elsewhere in codebase.

Adding New Anti-Patterns

When you discover a new recurring issue:

  1. Identify the category: CI/Workflow, Build/Packaging, or Application/Runtime
  2. Create the file in the appropriate subfolder with a descriptive name
  3. Follow the template:
    • Category
    • Issue (one-line summary)
    • Pattern to Avoid (code example)
    • Correct Approach (code example)
    • Why It Fails (root cause explanation)
    • Detection (how to find instances)
    • Test Reference (if automated test exists)
    • Related Commits (historical context)
  4. Update this index with the new anti-pattern
  5. Add automated test to your project's code pattern test file if feasible

Anti-pattern files: .claude/skills/code-sentinel/anti-patterns/