本文へ移動
cccskills
無料GitHub で公開

api-audit

Protocol for auditing API surface coherence and type safety. Trigger when: - Evaluating API designs, interface type safety, or design elegance. - Prompt contains: /api-audit, API surface, API coherence, type safety.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md15.6 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

API Coherence Audit Protocol

A thorough, piecemeal framework for auditing code API surfaces. Designed to maintain agent coherence by working iteratively through the codebase with explicit human checkpoints.

Adversarial path anchor. This lens is invoked on the Verification Dual's adversarial path (rules.md §2 Invariant 1): when no deterministic evaluator can close an API-surface correctness condition, context-free agents using this protocol supply the decorrelated review. See skills/refine/SKILL.md AUDIT §"Sibling Skills Consultation" for the wiring point.

Guiding Principle: An ideal API is minimal, well-scoped, type-safe, elegantly composable, and monosemic. It leverages language features to make error states unrepresentable.


Phase 0: Scope Definition

Before beginning, establish the audit scope with the user. Confirm: target language and version; type system strength; public API entry points; explicit exclusions (generated code, vendored deps); user-defined constraints (e.g., no breaking changes, no-std compatibility).

Checkpoint: Present scope to user for approval before proceeding.

Phase 1: Surface Discovery (Full Codebase Ingestion)

Objective: Build a complete mental model of the public API surface before any analysis.

1.1 Enumerate Public Surface

For each entry point, catalog:

  • Exported Types: Structs, enums, classes, interfaces, type aliases
  • Exported Functions: Free functions, associated functions, methods
  • Exported Constants: Public constants, static values
  • Re-exports: Items re-exported from internal modules
  • Traits/Interfaces: Abstractions meant for external implementation

1.2 Generate Surface Map

Produce a structured inventory:

## Module: `crate::auth`
### Types
- `Principal` (struct) — L23-L45
- `AuthState` (enum) — L47-L62
### Functions
- `Principal::verify(&self, sig: &Signature) -> Result<()>` — L67
- `validate_token(token: &str) -> Result<Claims>` — L89
### Traits
- `Authenticator` — L12-L21
  - `fn authenticate(&self, credentials: &Credentials) -> Result<Session>`

Checkpoint: Present surface map to user. Ask:

  1. Is this complete? Are there missing entry points?
  2. Are there items here that should NOT be public?

Phase 2: Iterative Component Audit

Objective: Audit each logical component systematically, one at a time.

Coherence Strategy: Analyze ONE component per iteration. Present findings. Await user acknowledgment before proceeding to the next.

Audit Dimensions

For each component, evaluate against all dimensions. Rate each: [PASS | WARN | FAIL]

Dimension A: Minimal Surface (Encapsulation)

The API should expose only what external consumers need.

CheckDescriptionAnti-Pattern
A.1Internal implementation details are hiddenpub on helper functions; _internal prefixes on public items
A.2Configuration uses sensible defaultsRequiring 10 parameters when 2 would suffice
A.3No "god objects" with excessive responsibilitySingle type with 50+ methods across unrelated concerns
A.4Private fields with controlled accessors where appropriateAll fields pub when mutation should be constrained
Remediation Patterns:
  • Use visibility modifiers (pub(crate), internal, private)
  • Builder pattern for complex construction
  • Facade pattern to simplify overly complex subsystems

Dimension B: Type Safety & Error Unrepresentability

Leverage the type system to make invalid states impossible to construct.

CheckDescriptionAnti-Pattern
B.1Domain values use newtypes, not primitivesuser_id: String instead of UserId(String)
B.2Enums are exhaustive over valid statesMagic strings like status: "pending" vs Status::Pending
B.3Result/Option used properly; no null/nil abuseReturning null for "not found" vs Option<T>
B.4Builder/factory patterns prevent invalid constructionPartially-constructed objects allowed to exist
B.5Phantom types or typestate for protocol enforcementState machine transitions not enforced at compile time
B.6Deserialization targets concrete typesDeserializing to Map<String, Any> then validating at runtime
Language-Specific Checks:
  • Rust: Proper #[non_exhaustive] usage; no unwrap in library code; correct Send/Sync bounds
  • Go: Proper error wrapping; unexported fields for invariants; meaningful zero values
  • TypeScript: Strict mode; no any; discriminated unions over string literals
  • Python: Type hints on public API; @dataclass for structured data; no Dict[str, Any] leakage Remediation Patterns:
  • Parse, don't validate (deserialize to concrete types)
  • Newtype pattern for domain primitives
  • Typestate pattern for state machines
  • #[must_use] on Result-returning functions

Dimension C: Composability & Self-Reuse

Higher-level APIs should compose lower-level primitives, not duplicate logic.

CheckDescriptionAnti-Pattern
C.1Higher abstractions compose lower onesConvenience function re-implements core logic
C.2Common patterns extracted to reusable utilitiesSame validation logic in 5 different functions
C.3Trait/interface hierarchies are coherentTrait with 20 methods when 3 would compose
C.4Extension points via composition, not inheritanceDeep inheritance hierarchies
Remediation Patterns:
  • Extract shared logic to internal helpers, call from public API
  • Use decorator/wrapper types for cross-cutting concerns
  • Prefer trait composition (+ OtherTrait) over monolithic traits

Dimension D: Monosemicity (One Path Per Concern)

Each concern should have exactly one canonical path through the API.

CheckDescriptionAnti-Pattern
D.1No redundant methods with overlapping functionalityget(), fetch(), retrieve() all doing the same thing
D.2Clear canonical path for common operations5 ways to create an instance, none obviously "correct"
D.3Deprecated paths actively marked and documentedOld API coexisting with new, neither marked deprecated
D.4No "stringly typed" APIs where enums would workmethod: "GET" instead of Method::Get
Remediation Patterns:
  • Consolidate redundant methods; deprecate legacy paths
  • Document the "happy path" prominently
  • Use #[deprecated] or equivalent with migration guidance

Dimension E: Naming & Cognitive Load

Names should be precise, consistent, and minimize mental overhead.

CheckDescriptionAnti-Pattern
E.1Consistent naming conventions throughoutgetUserById vs fetch_user vs user.get
E.2Names reflect precise semanticsprocess() instead of validateAndTransformInput()
E.3No abbreviations without project-wide glossarycrnt_req_hdlr instead of current_request_handler
E.4Boolean methods/fields use predicate namingvalid instead of is_valid or has_permission
Remediation Patterns:
  • Establish and document naming conventions in CONTRIBUTING.md
  • Rename for precision; use refactoring tools for safe migration

Dimension F: Error Handling Coherence

Errors should be informative, typed, and recoverable where possible.

CheckDescriptionAnti-Pattern
F.1Error types are domain-specific, not stringly-typedError::Generic(String) for everything
F.2Errors contain sufficient context for debugging"failed" vs "failed to parse config at line 42: expected integer"
F.3Recoverable errors distinct from fatal panicsPanicking on user input validation failure
F.4Error variants map to distinct recovery pathsSingle error type with no way to discriminate cause
Remediation Patterns:
  • Define enum error types per module/subsystem
  • Use thiserror/anyhow (Rust), errors.Is/As (Go), custom error classes (TS/Python)
  • Include structured context (file paths, line numbers, input values)

Iteration Template

For each component, produce:

## Audit: `module::Component`
### Summary
Brief description of the component's purpose and surface.
### Findings
| Dimension | Rating | Notes |
|:----------|:-------|:------|
| A. Minimal Surface | PASS | — |
| B. Type Safety | WARN | Uses `String` for user_id; newtype recommended |
| C. Composability | PASS | — |
| D. Monosemicity | FAIL | Redundant `create` and `new` methods |
| E. Naming | PASS | — |
| F. Error Handling | WARN | Generic error type; consider domain errors |
### Recommended Changes
1. **[D.1]** Consolidate `create` and `new` into single `new` constructor
2. **[B.1]** Introduce `UserId(String)` newtype
3. **[F.1]** Define `ComponentError` enum with specific variants
### Open Questions for User
1. Is backwards compatibility required for the `create` method?
2. Should `UserId` validation happen at construction time?

Checkpoint: Present findings for this component. Await acknowledgment before proceeding.

Phase 3: Cross-Cutting Analysis

After completing component audits, assess systemic patterns.

3.1 Consistency Audit

  • Naming conventions consistent across all modules
  • Error handling strategy uniform
  • Common patterns (e.g., builders, result types) applied uniformly
  • Documentation style consistent

3.2 Layering Audit

  • Clear dependency direction (lower layers don't import higher)
  • No circular dependencies between modules
  • Abstractions at appropriate levels (not too leaky, not too opaque)

3.3 Coherence Score

Rate the overall API coherence:

CriterionScore (1-5)Notes
Minimal Surface
Type Safety
Composability
Monosemicity
Naming Coherence
Error Handling
Overall

Phase 4: Remediation Plan

Synthesize findings into prioritized action items.

Priority Levels

  • P0 (Critical): Type safety gaps enabling invalid states; unhandled error conditions
  • P1 (High): Encapsulation violations; significant duplication
  • P2 (Medium): Naming inconsistencies; documentation gaps
  • P3 (Low): Style preferences; minor redundancies

Remediation Template

## Remediation Plan: [Project Name]
### P0 — Critical
1. [ ] [Module] Brief description — Links to finding
### P1 — High
1. [ ] [Module] Brief description — Links to finding
### P2 — Medium
1. [ ] [Module] Brief description — Links to finding
### P3 — Low
1. [ ] [Module] Brief description — Links to finding

Checkpoint: Present remediation plan for user approval before any code changes.

Appendix: Language-Specific Checklists

Rust

  • Public items have doc comments (///)
  • #[must_use] on Result-returning functions
  • #[non_exhaustive] on enums for future-proofing
  • No unwrap()/expect() in library code paths
  • Correct Send/Sync bounds on public types
  • pub(crate) for internal-only items
  • Feature flags documented with cfg_attr

Go

  • Exported types have doc comments
  • Error types implement Error and support Is/As
  • Unexported fields for invariant protection
  • Meaningful zero values or require constructors
  • Context propagation for cancellation
  • Options pattern for configurable constructors

TypeScript

  • Strict mode enabled; no any in public API
  • Discriminated unions over string literals
  • Readonly types for immutable data
  • Branded types for domain primitives
  • Proper error class hierarchy
  • Zod/io-ts for runtime validation of external input

Python

  • Type hints on all public functions and classes
  • @dataclass or pydantic for structured data
  • Enum for finite sets of values
  • __all__ defined in __init__.py
  • No Dict[str, Any] in public signatures
  • Docstrings follow consistent format (Google/NumPy/Sphinx)

Workflow Execution Summary

┌─────────────────────────────────────────────────────────────────┐
│ Phase 0: Scope Definition                                       │
│   → User approves scope                                         │
├─────────────────────────────────────────────────────────────────┤
│ Phase 1: Surface Discovery                                      │
│   → Full codebase ingestion                                     │
│   → Surface map generated                                       │
│   → User confirms completeness                                  │
├─────────────────────────────────────────────────────────────────┤
│ Phase 2: Iterative Component Audit                              │
│   ┌──────────────────────────────────────────────────────────┐  │
│   │ For each component:                                      │  │
│   │   → Analyze against 6 dimensions                         │  │
│   │   → Present findings                                     │  │
│   │   → Await user acknowledgment                            │  │
│   │   → Proceed to next component                            │  │
│   └──────────────────────────────────────────────────────────┘  │
├─────────────────────────────────────────────────────────────────┤
│ Phase 3: Cross-Cutting Analysis                                 │
│   → Consistency audit                                           │
│   → Layering audit                                              │
│   → Coherence scoring                                           │
├─────────────────────────────────────────────────────────────────┤
│ Phase 4: Remediation Plan                                       │
│   → Prioritized action items                                    │
│   → User approves before implementation                         │
└─────────────────────────────────────────────────────────────────┘

Final Directive

This protocol enforces iterative human engagement to maintain agent coherence. Never skip checkpoints. If context becomes unclear or findings accumulate beyond what can be tracked, pause and summarize progress before continuing. The goal is not merely to identify issues, but to cultivate a shared understanding of API quality between the auditor and the user.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

ai-audit

無料

SOP for auditing AI-generated code. Trigger when: - Reviewing, refactoring, or cleaning up AI-generated code to prevent regressions or hallucinated APIs. - Prompt contains: /ai-audit, code audit, AI cleanup, common flaws.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

boundary

無料

Normative sufficiency conditions for Initial Boundary Conditions (IBCs) and the SOP for the cheap-tier boundary refinement loop (/boundary). Trigger when: - Crafting, auditing, or refining a prompt/IBC destined for an expensive (architect-class) model or an autonomous worker dispatch. - Evaluating whether a task frame is sufficient to bound an agent walk. - Prompt contains: /boundary, IBC, initial boundary condition, boundary contract, sufficiency conditions, worker prompt, prompt refinement.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

campaign

無料

SOP for the architect-tier campaign workflow (/campaign): exhaustive survey, mitigation planning, tiered orchestration, and reconciliation. Trigger when: - Running a multi-workstream initiative where an expensive architect-tier council surveys, plans, emits worker prompts, and judges landed work. - Conducting production-readiness assessments that fan out into autonomous mitigation dispatches across model tiers. - Prompt contains: /campaign, campaign workflow, survey, orchestrate, reconcile, premise freshness, tier routing, worker IBC, scratch.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

chronicle

無料

Maintain and update the persistent project chronicle (docs/chronicle.md). Trigger when: - The human requests a history summary or chronicle update. - Starting work on a new codebase and needing context on its evolution. - Prompt contains keywords: /chronicle, chronicle, project history, git log summary, history summary.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

Rules, conventions, and constraints for formatting git commit messages and committing at logical boundaries. Trigger when: - Drafting, revising, or validating git commit messages. - Pausing at commit boundaries under the CORE or CONTINUE workflows. - Evaluating whether a changeset should be split into multiple commits. - Prompt contains keywords: commit message, git commit, conventional commits, commit hygiene, commit guidelines, logical boundary, spaghetti diff, atomic commit, commit boundary.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

Foundational ethics, authority hierarchy, and structural principles for the Predicate agent. Always-on law (composable system-prompt core): Truth>Harmony, Evidence>Authority, Halt>Assumption, Outcomes>Process — four ordered principles that govern every walk. Reference (by-moment): conflict resolution, ethics adjudication, novel situations, precedence walkthrough, entropy diagnostics, principled resistance. Trigger (reference depth): resolving rule conflicts, ethics calls, novel situations. Prompt contains: constitution, principles, precedence, truth over harmony, outcomes over process, evidence over authority, principled resistance.

日本語の概要は準備中です。原文の説明を表示しています。

nrdxp/predicate102026年9月1日 更新

nrdxp のスキルをすべて見る

このスキルの問題を報告する