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.
In this repository18 other files it gives its agents.
- codebase-designSkill
- principle-type-system-disciplineSkill
- swift-64-concurrencySkill
- swift-adversarial-pr-reviewSkill
- swift-api-design-guidelinesSkill
- swift-concurrencySkill
- swift-evaluate-paritySkill
- swift-functional-architectureSkill
- swift-functional-coreSkill
- swift-hexagonal-spmSkill
- swift-hook-xpcSkill
- swift-pr-orchestrationSkill
- swift-protocol-boundariesSkill
- swift-pr-reviewSkill
- swift-testing-proSkill
- swift-thermo-nuclear-reviewSkill
- swift-type-system-architectureSkill
- swift-value-semanticsSkill
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
- Distinctive: line 17
Test empty, maximum, truncated, misaligned, interrupted, closed, and allocation-failure paths.
- Distinctive: line 19
Read references/systems-boundary-guide.md before changing pointer or descriptor code.
- Very specific: line 23
Prefer Span/OutputSpan, withTemporaryAllocation, and safe RawSpan loads over raw pointer+count.
- Very specific: line 27
Never use @unchecked Sendable to paper over a raw pointer or handle whose synchronization/lifetime is unknown.
- Very specific: line 28
Never assume defer makes an aliased descriptor safe.
- Very specific: line 29
Never use memcpy/rebinding as a substitute for a typed lifetime argument.
- Distinctive: line 30
Keep system calls and unsafe blocks close to their checked wrapper.
≈ “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.
Files
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
- State the external contract: ownership, validity, alignment, initialization, length, errno behavior, blocking/cancellation, and cleanup.
- Wrap raw handles in a narrow type. Use
~Copyablewhen duplicate close/use-after-close is invalid; keep borrowed operations non-consuming. - Bound all lengths and arithmetic before allocation, pointer formation, or indexing. Reject malformed input before touching memory.
- 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.
- 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.
- 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 Sendableto paper over a raw pointer or handle whose synchronization/lifetime is unknown. - Never assume
defermakes 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.
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
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.

