Community程式設計與開發github.com

dotnet-slopwatch

使用 Slopwatch 在 .NET 程式碼變更中偵測 LLM 獎勵狩獵行為。每次程式碼修改後執行,以捕捉被停用的測試、被抑制的警告、空的 catch 區塊,以及其它掩蓋真正問題的捷徑。

dotnet-slopwatch 是什麼?

Slopwatch 是一個專門為 .NET 專案設計的命令列工具,用於偵測由大型語言模型(LLM)引入的「投機取巧」(slop)行為,例如停用測試、抑制警告或空的 catch 區塊。其主要目標是防止 LLM 為了讓測試通過或建置成功而採取捷徑,從而累積技術債務。工具支援本機或全域安裝,並可建立基線檔案以區分既有問題和新引入的問題。它可與 Claude Code 外掛整合,在每次編輯後自動驗證,並能在 GitHub Actions 和 Azure Pipelines 等 CI/CD 管線中作為品質閘道使用。Slopwatch 提供六條偵測規則,涵蓋已停用測試、警告抑制、空的 catch 區塊、任意延遲、專案層級抑制以及中央套件管理規避等模式,且所有規則皆可透過組態檔自訂。建議在 LLM 會話期間使用嚴格模式,將所有規則提升為錯誤等級,以達到最大保護效果。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Aaronontheweb/dotnet-skills/tree/main/skills/slopwatch

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Slopwatch:LLM 防作弊工具 for .NET

何時使用此技能

請持續使用此技能。 每當 LLM(包括 Claude)對以下檔案進行變更時:

  • C# 原始檔(.cs)
  • 專案檔(.csproj)
  • Props 檔(Directory.Build.props、Directory.Packages.props)
  • 測試檔

請執行 slopwatch 以驗證這些變更是否引入了「投機取巧」(slop)。

什麼是 Slop?

「Slop」指的是 LLM 為了讓測試通過或建置成功,而不實際解決根本問題所採取的捷徑。這些是獎勵狩獵行為——LLM 最佳化的是表面上的成功,而非真正的修復。

常見的 Slop 模式

模式範例為何有害
停用測試[Fact(Skip="flaky")]隱藏失敗,而非修復問題
警告抑制#pragma warning disable CS8618壓制編譯器,卻未修復問題
空的 catch 區塊catch (Exception) { }吞掉錯誤,隱藏臭蟲
任意延遲await Task.Delay(1000);掩蓋競爭條件,拖慢測試
專案層級抑制<NoWarn>CS1591</NoWarn>整個專案關閉警告
CPM 規避行內 Version="1.0.0"破壞中央套件管理

絕不接受這些模式。 如果 LLM 引入了 slop,請拒絕該變更並要求正確的修復。


安裝

作為本機工具(建議)

將以下內容新增至 .config/dotnet-tools.json:

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "slopwatch.cmd": {
      "version": "0.2.0",
      "commands": ["slopwatch"],
      "rollForward": false
    }
  }
}

然後還原:

dotnet tool restore

作為全域工具

dotnet tool install --global Slopwatch.Cmd

首次設定:建立基線

在現有專案上使用 slopwatch 之前,請先建立當前問題的基線:

# 從現有程式碼初始化基線
slopwatch init

# 這會建立 .slopwatch/baseline.json
git add .slopwatch/baseline.json
git commit -m "Add slopwatch baseline"

為什麼需要基線? 舊程式碼可能存在既有問題。基線確保 slopwatch 只會捕捉新引入的 slop,而不是既有的技術債務。


在 LLM 會話期間的使用方式

每次程式碼變更後

在每次 LLM 生成的程式碼修改後執行 slopwatch:

# 分析新問題(使用基線)
slopwatch analyze

# 使用嚴格模式——警告也會被視為失敗
slopwatch analyze --fail-on warning

當 Slopwatch 標記問題時

請勿忽略。 相反地:

  1. 了解原因——LLM 為何選擇捷徑
  2. 要求正確修復——具體指出問題所在
  3. 驗證修復——確保沒有引入不同的 slop
# 範例:LLM 停用了一個測試
❌ SW001 [Error]: 偵測到已停用的測試
   File: tests/MyApp.Tests/OrderTests.cs:45
   Pattern: [Fact(Skip="Test is flaky")]

# 正確回應:要求實際修復
「這個測試被停用而不是被修復。請調查它為什麼不穩定,並修復底層的時序/競爭條件問題。」

更新基線(罕見情況)

只有在 slop 確實正當且有文件記錄時,才更新基線:

# 將當前偵測結果加入基線(請謹慎使用!)
slopwatch analyze --update-baseline

正當理由範例:

  • 第三方程式庫強制使用某種模式(例如必須抑制特定警告)
  • 為速率限制而設置的故意延遲(而非測試不穩定)
  • 無法修改的生成程式碼

更新基線時,請在程式碼註解中說明原因。


Claude Code 外掛整合

將 slopwatch 新增為外掛,以自動驗證每次編輯。建立或更新 .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "slopwatch analyze -d . --hook",
            "timeout": 60000
          }
        ]
      }
    ]
  }
}

--hook 旗標:

  • 僅分析 git 髒檔案(即使在大型儲存庫中也很快速)
  • 將錯誤以可讀格式輸出至 stderr
  • 在警告/錯誤時阻止編輯(退出碼 2)
  • Claude 會看到錯誤並能立即修復

CI/CD 整合

將 slopwatch 作為品質關卡加入 CI 管線:

GitHub Actions

jobs:
  slopwatch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '9.0.x'

      - name: Install Slopwatch
        run: dotnet tool install --global Slopwatch.Cmd

      - name: Run Slopwatch
        run: slopwatch analyze -d . --fail-on warning

Azure Pipelines

- task: DotNetCoreCLI@2
  displayName: 'Install Slopwatch'
  inputs:
    command: 'custom'
    custom: 'tool'
    arguments: 'install --global Slopwatch.Cmd'

- script: slopwatch analyze -d . --fail-on warning
  displayName: 'Slopwatch Analysis'

偵測規則

規則嚴重程度偵測內容
SW001錯誤已停用的測試(Skip=、Ignore、#if false)
SW002警告警告抑制(#pragma warning disable、SuppressMessage)
SW003錯誤吞掉例外狀況的空 catch 區塊
SW004警告測試中的任意延遲(Task.Delay、Thread.Sleep)
SW005警告專案檔中的 slop(NoWarn、TreatWarningsAsErrors=false)
SW006警告CPM 規避(VersionOverride、行內 Version 屬性)

設定

建立 .slopwatch/slopwatch.json 以進行自訂:

{
  "minSeverity": "warning",
  "rules": {
    "SW001": { "enabled": true, "severity": "error" },
    "SW002": { "enabled": true, "severity": "warning" },
    "SW003": { "enabled": true, "severity": "error" },
    "SW004": { "enabled": true, "severity": "warning" },
    "SW005": { "enabled": true, "severity": "warning" },
    "SW006": { "enabled": true, "severity": "warning" }
  },
  "exclude": [
    "**/Generated/**",
    "**/obj/**",
    "**/bin/**"
  ]
}

嚴格模式(建議 LLM 會話使用)

為了在 LLM 編碼會話期間獲得最大保護,請將所有規則提升為錯誤:

{
  "minSeverity": "warning",
  "rules": {
    "SW001": { "enabled": true, "severity": "error" },
    "SW002": { "enabled": true, "severity": "error" },
    "SW003": { "enabled": true, "severity": "error" },
    "SW004": { "enabled": true, "severity": "error" },
    "SW005": { "enabled": true, "severity": "error" },
    "SW006": { "enabled": true, "severity": "error" }
  }
}

哲學:對新的 Slop 零容忍

  1. 基線捕捉舊有問題——既有問題被承認但隔離
  2. 新的 Slop 被阻擋——任何新的捷徑都會導致建置/編輯失敗
  3. 例外需要正當理由——如果必須更新基線,請記錄原因
  4. LLM 並不特別——同樣的規則適用於人類和 AI 生成的程式碼

目標是防止 LLM 為了「讓測試通過」而非「修復實際問題」所導致的技術債務逐漸累積。


快速參考

# 首次設定
slopwatch init
git add .slopwatch/baseline.json

# 每次 LLM 程式碼變更後
slopwatch analyze

# 嚴格模式(建議)
slopwatch analyze --fail-on warning

# 含統計資料(效能除錯)
slopwatch analyze --stats

# 更新基線(罕見,請記錄原因)
slopwatch analyze --update-baseline

# JSON 輸出(供工具使用)
slopwatch analyze --output json

何時覆寫(幾乎從不)

更新基線或停用規則的唯一正當理由:

情境動作必要條件
第三方強制模式更新基線程式碼註解說明原因
生成的程式碼(無法修改)加入排除清單在組態中記錄
故意設定的速率限制延遲更新基線程式碼註解,不在測試中
舊程式碼清理一次性基線更新PR 描述

無效理由:

  • 「測試不穩定」→ 修正不穩定性
  • 「警告很煩人」→ 修正程式碼
  • 「在我的機器上可以跑」→ 修正競爭條件
  • 「我們稍後再修」→ 現在就修

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

akka-hosting-actor-patterns

Patterns for building entity actors with Akka.Hosting - GenericChildPerEntityParent, message extractors, cluster sharding abstraction, akka-reminders, and ITimeProvider. Supports both local testing and clustered production modes.

akka-net-aspire-configuration

Configure Akka.NET with .NET Aspire for local development and production deployments. Covers actor system setup, clustering, persistence, Akka.Management integration, and Aspire orchestration patterns.

akka-net-best-practices

Critical Akka.NET best practices including EventStream vs DistributedPubSub, supervision strategies, error handling, Props vs DependencyResolver, work distribution patterns, and cluster/local mode abstractions for testability.

akka-net-management

Akka.Management for cluster bootstrapping, service discovery (Kubernetes, Azure, Config), health checks, and dynamic cluster formation without static seed nodes.

akka-net-testing-patterns

Write unit and integration tests for Akka.NET actors using modern Akka.Hosting.TestKit patterns. Covers dependency injection, TestProbes, persistence testing, and actor interaction verification. Includes guidance on when to use traditional TestKit.

api-design

Design stable, compatible public APIs using extend-only design principles. Manage API compatibility, wire compatibility, and versioning for NuGet packages and distributed systems.

aspire-configuration

Configure Aspire AppHost to emit explicit app config via environment variables; keep app code free of Aspire clients and service discovery.

aspire-integration-testing

Write integration tests using .NET Aspire

aspire-service-defaults

Create a shared ServiceDefaults project for Aspire applications. Centralizes OpenTelemetry, health checks, resilience, and service discovery configuration across all services.

crap-analysis

Analyze code coverage and CRAP (Change Risk Anti-Patterns) scores to identify high-risk code. Use OpenCover format with ReportGenerator for Risk Hotspots showing cyclomatic complexity and untested code paths.

csharp-concurrency-patterns

Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.

database-performance

Database access patterns for performance. Separate read/write models, avoid N+1 queries, use AsNoTracking, apply row limits, and never do application-side joins. Works with EF Core and Dapper.

dependency-injection-patterns

Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.

dotnet-devcert-trust

Diagnose and fix .NET HTTPS dev certificate trust issues on Linux. Covers the full certificate lifecycle from generation to system CA bundle inclusion, with distro-specific guidance for Ubuntu, Fedora, Arch, and WSL2.

dotnet-local-tools

Managing local .NET tools with dotnet-tools.json for consistent tooling across development environments and CI/CD pipelines.

dotnet-project-structure

Modern .NET project structure including .slnx solution format, Directory.Build.props, central package management, SourceLink, version management with RELEASE_NOTES.md, and SDK pinning with global.json.

efcore-patterns

Entity Framework Core best practices including NoTracking by default, query splitting for navigation collections, migration management, dedicated migration services, and common pitfalls to avoid.

ilspy-decompile

Understand implementation details of .NET code by decompiling assemblies. Use when you want to see how a .NET API works internally, inspect NuGet package source, view framework implementation, or understand compiled .NET binaries.

mailpit-integration

Test email sending locally using Mailpit with .NET Aspire. Captures all outgoing emails without sending them. View rendered HTML, inspect headers, and verify delivery in integration tests.

marketplace-publishing

Workflow for publishing skills and agents to the dotnet-skills Claude Code marketplace. Covers adding new content, updating plugin.json, validation, and release tagging.

相關技能