agentleFS
MovGP0MovGP0/Skills/unsafe-checker/AGENTS.md

Skills / unsafe-checker

AGENTS.md1 starsChanged 4 months agoMITView on GitHub

Auto-generated from rules/

We split this AGENTS.md into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before every unsafe block:

    line 122

≈ “Common” is an estimate: at least 1 in 5 of the 36,368 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Unsafe Checker - Quick Reference

Auto-generated from rules/

Rule Summary by Section

General Principles (3 rules)

IDLevelTitle
general-01PDo Not Abuse Unsafe to Escape Compiler Safety Checks
general-02PDo Not Blindly Use Unsafe for Performance
general-03GDo Not Create Aliases for Types/Methods Named "Unsafe"

Safety Abstraction (11 rules)

IDLevelTitle
safety-01PBe Aware of Memory Safety Issues from Panics
safety-02PUnsafe Code Authors Must Verify Safety Invariants
safety-03PDo Not Expose Uninitialized Memory in Public APIs
safety-04PAvoid Double-Free from Panic Safety Issues
safety-05PConsider Safety When Manually Implementing Auto Traits
safety-06PDo Not Expose Raw Pointers in Public APIs
safety-07PProvide Unsafe Counterparts for Performance Alongside Safe Methods
safety-08PMutable Return from Immutable Parameter is Wrong
safety-09PAdd SAFETY Comment Before Any Unsafe Block
safety-10GAdd Safety Section in Docs for Public Unsafe Functions
safety-11GUse assert! Instead of debug_assert! in Unsafe Functions

Raw Pointers (6 rules)

IDLevelTitle
ptr-01PDo Not Share Raw Pointers Across Threads
ptr-02PPrefer NonNull<T> Over *mut T
ptr-03PUse PhantomData<T> for Variance and Ownership
ptr-04GDo Not Dereference Pointers Cast to Misaligned Types
ptr-05GDo Not Manually Convert Immutable Pointer to Mutable
ptr-06GPrefer pointer::cast Over as for Pointer Casting

Union (2 rules)

IDLevelTitle
union-01PAvoid Union Except for C Interop
union-02PDo Not Use Union Variants Across Different Lifetimes

Memory Layout (6 rules)

IDLevelTitle
mem-01PChoose Appropriate Data Layout for Struct/Tuple/Enum
mem-02PDo Not Modify Memory Variables of Other Processes
mem-03PDo Not Let String/Vec Auto-Drop Other Process's Memory
mem-04PPrefer Reentrant Versions of C-API or Syscalls
mem-05PUse Third-Party Crates for Bitfields
mem-06GUse MaybeUninit<T> for Uninitialized Memory

FFI (18 rules)

IDLevelTitle
ffi-01PAvoid Passing Strings Directly to C
ffi-02PRead Documentation Carefully for std::ffi Types
ffi-03PImplement Drop for Wrapped C Pointers
ffi-04PHandle Panics When Crossing FFI Boundaries
ffi-05PUse Portable Type Aliases from std or libc
ffi-06PEnsure C-ABI String Compatibility
ffi-07PDo Not Implement Drop for Types Passed to External Code
ffi-08PHandle Errors Properly in FFI
ffi-09PUse References Instead of Raw Pointers in Safe Wrappers
ffi-10PExported Functions Must Be Thread-Safe
ffi-11PBe Careful with repr(packed) Field References
ffi-12PDocument Invariant Assumptions for C Parameters
ffi-13PEnsure Consistent Data Layout for Custom Types
ffi-14PTypes in FFI Should Have Stable Layout
ffi-15PValidate Non-Robust External Values
ffi-16PSeparate Data and Code for Closures to C
ffi-17PUse Opaque Types Instead of c_void
ffi-18PAvoid Passing Trait Objects to C

I/O Safety (1 rule)

IDLevelTitle
io-01PEnsure I/O Safety When Using Raw Handles

Clippy Lint Mapping

Clippy LintRuleCategory
undocumented_unsafe_blockssafety-09SAFETY comments
missing_safety_docsafety-10Safety docs
panic_in_result_fnsafety-01, ffi-04Panic safety
non_send_fields_in_send_tysafety-05Send/Sync
uninit_assumed_initsafety-03Initialization
uninit_vecmem-06Initialization
mut_from_refsafety-08Aliasing
cast_ptr_alignmentptr-04Alignment
cast_ref_to_mutptr-05Aliasing
ptr_as_ptrptr-06Pointer casting
unaligned_referencesffi-11Packed structs
debug_assert_with_mut_callsafety-11Assertions

Quick Decision Tree

Writing unsafe code?
    │
    ├─ FFI with C?
    │   └─ See ffi-* rules
    │
    ├─ Raw pointers?
    │   └─ See ptr-* rules
    │
    ├─ Manual Send/Sync?
    │   └─ See safety-05
    │
    ├─ MaybeUninit/uninitialized?
    │   └─ See safety-03, mem-06
    │
    └─ Performance optimization?
        └─ See general-02, safety-07

Essential Checklist

Before every unsafe block:

  • SAFETY comment present
  • Invariants documented
  • Pointer validity checked
  • Aliasing rules followed
  • Panic safety considered
  • Tested with Miri

Resources

  • checklists/before-unsafe.md - Pre-writing checklist
  • checklists/review-unsafe.md - Code review checklist
  • checklists/common-pitfalls.md - Common bugs and fixes
  • examples/safe-abstraction.md - Safe wrapper patterns
  • examples/ffi-patterns.md - FFI best practices

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.