agentleFS
christopherkaranichristopherkarani/rv/.claude/skills/swift-systems-safety/SKILL.md

swift-systems-safety

Skill8 starsChanged 6 days agoApache-2.0View on GitHub

Use when Swift touches POSIX, file descriptors, sockets, pointers, buffers, C ABI, mmap, unsafe code, or manual cleanup. Do not invoke for ordinary safe collection code.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test empty, maximum, truncated, misaligned, interrupted, closed, and allocation-failure paths.

    line 17
  2. Distinctive:

    Read references/systems-boundary-guide.md before changing pointer or descriptor code.

    line 19
  3. Very specific:

    Prefer Span/OutputSpan, withTemporaryAllocation, and safe RawSpan loads over raw pointer+count.

    line 23
  4. Very specific:

    Never use @unchecked Sendable to paper over a raw pointer or handle whose synchronization/lifetime is unknown.

    line 27
  5. Very specific:

    Never assume defer makes an aliased descriptor safe.

    line 28
  6. Very specific:

    Never use memcpy/rebinding as a substitute for a typed lifetime argument.

    line 29
  7. Distinctive:

    Keep system calls and unsafe blocks close to their checked wrapper.

    line 30

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill 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
SKILL.md

Swift systems safety

Make every unsafe boundary small, typed, bounded, and lifetime-proven. Unsafe APIs are escape hatches from static guarantees, not implementation style.

Procedure

  1. State the external contract: ownership, validity, alignment, initialization, length, errno behavior, blocking/cancellation, and cleanup.
  2. Wrap raw handles in a narrow type. Use ~Copyable when duplicate close/use-after-close is invalid; keep borrowed operations non-consuming.
  3. Bound all lengths and arithmetic before allocation, pointer formation, or indexing. Reject malformed input before touching memory.
  4. Bind and access memory only for the documented lifetime and alignment. Do not assume a byte buffer is bound to an arbitrary typed value; do not escape pointers from their closure/lifetime.
  5. Translate C/POSIX results immediately into typed Swift outcomes. Preserve errno at the call site, retry only interruptible operations where the contract allows, and distinguish EOF, would-block, timeout, and failure.
  6. Test empty, maximum, truncated, misaligned, interrupted, closed, and allocation-failure paths. Run sanitizers or platform diagnostics when available.

Read references/systems-boundary-guide.md before changing pointer or descriptor code.

Swift 6.4

Prefer Span/OutputSpan, withTemporaryAllocation, and safe RawSpan loads over raw pointer+count. C/C++ export and std::span bridging go through swift-64-interop-c. POSIX/fd/mmap rules in this skill still apply.

Guardrails

  • Never use @unchecked Sendable to paper over a raw pointer or handle whose synchronization/lifetime is unknown.
  • Never assume defer makes an aliased descriptor safe; prove single ownership.
  • Never use memcpy/rebinding as a substitute for a typed lifetime argument.
  • Keep system calls and unsafe blocks close to their checked wrapper; do not spread raw integers through the domain.

Completion contract

Report the safety invariant, bounds and lifetime proof, cleanup ownership, error mapping, and the strongest platform-specific verification performed.

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.