README.md

modern-swift

modern-swift is a set of three agent skills for writing, reviewing, and porting Swift. The rules describe Swift 6.4 in the Swift 6 language mode. The repository also holds lint settings for the rules a tool can check, and graded tasks that measure whether an agent follows each skill.

Install

bash
1npx skills add https://git.cafe/dynd/modern-swift.git

The skills

SkillThe agent uses it when you ask it toIt produces
swift-best-practiceswrite, change, refactor, or debug SwiftSwift code that passes swift build and swift format lint
swift-reviewreview, audit, or check Swifta report with ranked findings, and no code changes
swift-portport TypeScript, JavaScript, Python, or Kotlin to Swifta Swift package, ported tests, and PORTING.md

swift-review and swift-port apply the rules in swift-best-practices, so install all three together.

How swift-best-practices is organized

The skill tells the agent to start with the simplest form and to move on only for a stated reason.

NeedStart withMove on when
Datastruct or enumthe value needs identity, sharing, or inheritance
Polymorphismsome P or a genericone collection must hold different types
Executionsynchronous code on the main actora profile shows a hang
Safetythe safe APIC interop needs a pointer

SKILL.md holds the rules that every task needs. A reference file holds the rules for one kind of task, and the agent reads it only when that kind of task comes up.

text
1skills/swift-best-practices/
2├── SKILL.md # data, errors, concurrency, generics, API design
3└── references/
4 ├── api-design-guidelines.md # naming or documenting a public API
5 ├── concurrency.md # isolation errors, callbacks, moving to Swift 6
6 ├── swift-testing.md # the user asked for tests
7 ├── swiftui.md # the target imports SwiftUI
8 ├── performance-and-arc.md # a profile shows a cost, or a retain cycle
9 ├── unsafe-and-interop.md # C interop or pointers
10 ├── macros.md # writing a macro
11 ├── logging.md # adding logs
12 └── google-swift-style.md # formatting questions

Most rules come with a code example, and each swift example in the skills compiles on Swift 6.4.2 without warnings. For example, the skill shows the rule "use one enum for states that exclude each other" as a change to a struct.

diff
1 struct Upload {
2- var isUploading = false
3- var progress: Double?
4- var error: (any Error)?
5- var resultURL: URL?
6+ enum State {
7+ case idle
8+ case uploading(progress: Double)
9+ case failed(any Error)
10+ case finished(URL)
11+ }
12+ var state = State.idle
13 }

How swift-review works

text
1review(target)
2 1. decide the scope file, package, or diff; library or app; Swift version
3 2. run the tools swift build, swift format lint, swift test
4 3. read for problems correctness, errors, API design, idiom, docs
5 4. write the report Must fix, Should fix, Consider, What is already good
6 5. offer the lint settings

Each finding gives a file:line location, the rule and its source, and the fix as a short change.

markdown
1### 1. The continuation never resumes on failure (`Sources/Feed/FeedView.swift:50`)
2
3**Rule:** A continuation must resume exactly once on every path (swift-best-practices, section 6)
4**Problem:** When the request fails, `data` is `nil` and nothing resumes, so the spinner never stops.
5**Fix:** resume with the error in an `else` branch.

How swift-port works

text
1port(source)
2 1. list the original's observable behavior
3 2. port the tests to Swift Testing
4 3. design the Swift API, then implement it
5 4. keep the port in proportion to the original
6 5. run swift build and swift test
7 6. write PORTING.md

The skill has a mapping table for each source language. Some rows are below.

In the originalIn Swift
TypeScript union of string literalsenum with String raw values
TypeScript Promise.allasync let, or a task group
Python exception hierarchyone error enum with associated values
Python dict in insertion orderan array of pairs, because Dictionary has no stable order
Kotlin sealed classenum with associated values

Lint settings

lints/ holds the compiler settings and the swift format rules that report the rules a tool can check. Copy the settings array from lints/Package.swift into your own Package.swift, and copy lints/.swift-format to the root of your project. The swift-review skill ships the same file as assets/swift-format.json, so an installed skill always has it.

text
1lints/
2├── Package.swift # upcoming features, strict memory safety, default isolation
3├── .swift-format # a link to skills/swift-review/assets/swift-format.json
4└── check/ # one Swift file for each rule, written to trigger its warning

To confirm that each setting still reports its rule, run the two commands below. Each file in check/ names the warning it expects in its first line.

bash
1cd lints
2swift build
3swift format lint --recursive check

Evals

An eval is a task for an agent, with one grader file for each behavior the result should show. The format matches the evals in BeautifulRust.

text
1skills/<skill>/evals/<case>/
2├── case.yaml # the name and the expected outcome
3├── prompt.md # what the user asks
4├── files/ # the starting files, if the task has any
5├── place-files.sh # copies files/ into the working folder
6└── graders/ # one file per expected behavior
SkillEvalThe task
swift-best-practiceslog-summary-cliwrite a command line tool that must not crash on bad input
swift-best-practicesrefactor-inventory-moduleremove planted problems and keep the behavior
swift-best-practicesphoto-pipeline-concurrencymove slow work off the main actor without unsafe shortcuts
swift-reviewreview-inventory-modulefind the planted problems and leave the code unchanged
swift-reviewreview-swiftui-feedfind the concurrency faults and accept SwiftUI conventions
swift-portport-python-task-graphport a Python module and its 12 tests
swift-portport-typescript-cart-pricingport a TypeScript module and its 26 tests

The repository has no script that runs the evals. Use a runner that reads the BeautifulRust format.

Sources

The rules draw on the Swift API Design Guidelines, the Swift 6 migration guide, the Swift Testing documentation, and the Google Swift Style Guide. The layout of the skills and the evals follows BeautifulRust.

License

The repository is under the MIT license, which is in LICENSE.