audit-pattern

GitHub

用于审查现有代码库中的设计模式是否符合生产级规范。通过比对文档不变量,识别模式误标、实现偏差或缺失,确保架构正确性,而非仅凭名称判断。

plugins/pattern-skills/skills/audit-pattern/SKILL.md Totoro-jam/battle-tested-patterns

Trigger Scenarios

audit our architecture against best practices do we implement X correctly are our patterns right pattern conformance is this really a <pattern>?

Install

npx skills add Totoro-jam/battle-tested-patterns --skill audit-pattern -g -y
More Options

Non-standard path

npx skills add https://github.com/Totoro-jam/battle-tested-patterns/tree/main/plugins/pattern-skills/skills/audit-pattern -g -y

Use without installing

npx skills use Totoro-jam/battle-tested-patterns@audit-pattern

指定 Agent (Claude Code)

npx skills add Totoro-jam/battle-tested-patterns --skill audit-pattern -a claude-code -g -y

安装 repo 全部 skill

npx skills add Totoro-jam/battle-tested-patterns --all -g -y

预览 repo 内 skill

npx skills add Totoro-jam/battle-tested-patterns --list

SKILL.md

Frontmatter
{
    "name": "audit-pattern",
    "description": "Use when reviewing or auditing an existing codebase against production-proven implementation patterns — checking whether the patterns it already implements (actor model, rate limiter, circuit breaker, LRU cache, write-ahead log, semaphore, ...) actually honor the canonical invariants, whether any are mislabeled (a \"semaphore\" that is really a mutex; an \"MVCC\" that keeps one version), whether any diverge from the reference, and which catalog patterns are absent. Triggers on \"audit our architecture against best practices\", \"do we implement X correctly\", \"are our patterns right\", \"pattern conformance\", \"is this really a <pattern>?\". This grades patterns already present; its companion adopt-pattern adds new ones."
}

Audit Patterns

Overview

Grade a codebase against the Battle-Tested Patterns catalog: for each pattern it implements, fetch the canonical doc page and check the implementation against that doc's invariants — not against the name the codebase gave it. The most valuable output of an audit is not a score; it is the mislabel — code called a "semaphore" that is actually a mutex, an "MVCC" that keeps a single version. Those are the claims that mislead developers into expecting guarantees the code does not provide.

Companion skill: Inventory using the adopt-pattern skill's catalog, or the pattern docs at https://github.com/Totoro-jam/battle-tested-patterns/tree/main/docs/patterns. This skill is the inverse of adopt-pattern: that one runs the catalog forward (add a pattern); this one runs it backward (grade patterns already there).

When to use

  • A reviewer asks whether a codebase's patterns are implemented correctly.
  • Someone asks "is this really a <pattern>?" or "do we honor X's invariants?".
  • A periodic conformance check after a release, to catch new mislabels/drift.

When NOT to use: adding a new pattern (use adopt-pattern), or general code review with no pattern claim in play.

Workflow

1. Inventory

List the catalog patterns the codebase implements. Match by shape, not name — a class named RateLimiter may be a different pattern, and a circuit breaker may exist unnamed. Hunt by shape: retry/backoff loops, lock or lease primitives, caches with eviction, state enums with transition switches, ring/circular buffers, breaker/trip counters, subscriber lists. Record the file(s) for each candidate. Only inventory patterns the codebase actually engages; do not pad the audit with absent ones.

2. Conformance — fetch the doc, never grade from memory

For each candidate, fetch the canonical doc page and read Core Idea (the invariant), When NOT to Use, and Production Proof (the reference shape). Then read the actual implementation. Grade against the doc's headline invariant.

3. Gap analysis — classify the deviation

Assign a verdict (scale below). The judgment is distinguishing faithful from divergent from mislabeled:

  • Meets the invariant faithfully → ✅
  • Meets the intent a different way (different algorithm/model) → 🟡
  • The developer/framework enables it but does not provide it → 🔵
  • It is actually a different catalog pattern → 🔁 (the mislabel — flag loudly)
  • Not present → ⚪ (absence is N/A, not a failure, unless the pattern is clearly needed)

4. Evidence — cite code + doc

Every verdict cites a file:line in the codebase and the doc invariant it was graded against. A verdict without a citation is an opinion, not an audit.

Verdict scale

Symbol Meaning
Faithful — honors the doc's headline invariant.
🟡 Intent met, model/algorithm diverges from the reference.
🔵 Enabled, not provided — the developer brings it.
🔁 Mislabeled — it is actually a different catalog pattern.
Absent / N-A — not present (only a gap if the pattern is needed).

Scorecard format (the output)

Produce one table, optionally grouped by catalog category:

Pattern Verdict Evidence & note
name sym path:line — one-line check against the doc's invariant

Then 2–4 headline findings, leading with the mislabels (🔁) and real gaps — those are what the audit is for. Faithful rows are reassurance, not the point.

Common mistakes

  • Grading from memory instead of fetching the doc — invents invariants. Fetch every candidate's doc page.
  • Accepting the code's own label — you will rubber-stamp a mutex called "Semaphore." Grade against the doc, not the class name.
  • Treating absence as a bug — a pattern not present is ⚪/N-A unless the codebase clearly needs it.
  • Verdicts without file:line — an audit is evidence, not vibes.
  • Auditing all 46 — grade only the patterns the codebase engages.

Example (compressed)

Auditing an HTTP/MCP framework:

Pattern Verdict Evidence & note
Actor Model in-memory-runtime.ts:144,156 — per-identity serialized turns; handler gets a clone, rollback on throw.
Semaphore 🔁 redis-actor-runtime.ts:18 — the lease is SET NX (count=1) = mutex; the doc routes max=1 → mutex.
MVCC 🟡 in-memory-runtime.ts:113 — lease-free reads never block writers, but only one version is kept (snapshot read, not multi-version).
Circuit Breaker Absent across all packages — a real gap for an outbound-heavy framework.

Headline: two over-claims (Semaphore→mutex, MVCC→single-version) that would mislead a developer expecting counting-semaphore or multi-version guarantees; one genuine gap (no circuit breaker).

Version History

  • 0307be9 Current 2026-07-05 14:53

Same Skill Collection

.claude/skills/diagnose/SKILL.md
.claude/skills/new-pattern/SKILL.md
.claude/skills/verify-source/SKILL.md
plugins/pattern-skills/skills/adopt-pattern/SKILL.md

Metadata

Files
0
Version
0307be9
Hash
b80cc7b8
Indexed
2026-07-05 14:53

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-08 15:17
浙ICP备14020137号-1 $bản đồ khách truy cập$