swift-ai-provider-kit
Copilot instructions1 starsChanged 8 months agoMITView on GitHub
AIProviderKit is a Swift 6 package providing a provider-agnostic abstraction layer for AI models. Three shipped modules: AIProviderKit (core, zero deps), ClaudeProvider (Anthropic), AppleIntelligenceProvider (on-device). Swift 6 strict concurrency with full Sendable compliance throughout.
- Reads credentials
We split this copilot-instructions.md into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Use actor for all mutable shared state.
- Very specific: line 13
Use async/await and structured concurrency (withThrowingTaskGroup).
- Very specific: line 24
Every provider must follow the mapper pattern: a dedicated XRequestMapper and XResponseMapper.
- Very specific: line 33
Prefer value types (struct, enum) over reference types unless actor semantics or identity are required.
- Very specific: line 34
Avoid force unwraps (!) and try!
- Distinctive: line 36
No magic strings or numbers.
- Distinctive: line 44
All tests follow given / when / then with section comments.
≈ “Common” is an estimate: at least 1 in 5 of the 3,669 Copilot instructions 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
AIProviderKit — Copilot Code Review Instructions
Project Overview
AIProviderKit is a Swift 6 package providing a provider-agnostic abstraction layer for AI models. Three shipped modules: AIProviderKit (core, zero deps), ClaudeProvider (Anthropic), AppleIntelligenceProvider (on-device). Swift 6 strict concurrency with full Sendable compliance throughout.
Swift & Concurrency
- Enforce Swift 6 strict concurrency. Every type crossing actor boundaries must be
Sendable. - Use
actorfor all mutable shared state. Preferactoroverclass+ locks. - Use
async/awaitand structured concurrency (withThrowingTaskGroup). Flag any GCD,DispatchQueue, or callback-based patterns. final classis acceptable only when the type holds exclusivelySendabledependencies and has no mutable state after init.@unchecked Sendablemust have an accompanying comment explaining why it is safe.- Flag
nonisolatedon actor methods unless the method only readsletproperties.
Architecture Rules
AIClientis the only coordinator. No new type should import details of a specific provider.- New providers must conform to
AIProvider(orAIStreamableProviderfor streaming support). No changes toAIClientor core types are required or acceptable. - Every provider must follow the mapper pattern: a dedicated
XRequestMapperandXResponseMapper. No mapping logic inside the provider class itself. ContentBlockis the universal content currency. Providers must map to/from it; they must not leak provider-specific types intoAIProviderKit.JSONValueis the required type for all tool inputs and outputs. Flag any use ofAny,[String: Any], orAnyCodable.- Registries (
ToolRegistry,SkillRegistry,RecipeRegistry) are actors. Access must beawaited; never store a registry reference outside an actor context.
Code Style
- Prefer value types (
struct,enum) over reference types unless actor semantics or identity are required. - Avoid force unwraps (
!) andtry!. Useguard letor propagate errors. - Errors must conform to the project's
AIErrortype or a clearly named domain error. Avoid barethrow NSError(...). - No magic strings or numbers. Constants belong in extensions or enums.
- File names must match the primary type they define (e.g.,
ClaudeRequestMapper.swift).
Testing
- Tests use Swift Testing (
import Testing,@Suite,@Test,#expect). Flag any use of XCTest. - All tests follow given / when / then with section comments.
- Mocks live in
Tests/<Target>/Mocks/. No inline ad-hoc stubs. - Provider tests must inject
MockHTTPClient— never hit real network endpoints. AIClienttests useMockAIProviderorSequentialMockProviderfor multi-turn scenarios.- Integration tests (under
Sources/IntegrationTests/) requireANTHROPIC_API_KEYand are opt-in only.
Documentation
- Diagrams use Mermaid only (
graph,sequenceDiagram,flowchart). Flag ASCII art diagrams. - Public API additions require a corresponding entry in
Documentation/Architecture.mdorDocumentation/UseCases.md. - New provider walkthroughs go in
Documentation/AddingAProvider.md.
Security
- API keys must never be hardcoded. Use
AuthorizationProviderinjection. - Flag any
print()orNSLog()calls that could leak tokens or user data. UseAILoggerinstead. - HTTP requests must go through
HTTPClientprotocol — never callURLSessiondirectly in provider or mapper code.
Where files are headingNew Copilot instructions files have more rules about branches and pull requests, and fewer about code style.
Of the Copilot instructions files we read, the 2,297 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-providerSkill
- add-toolSkill
- commitSkill
- lintSkill
- pr-comment-fixerSkill
- swift-architecture-skillSkill
- swift-concurrency-proSkill
- swift-testing-proSkill
- swiftui-proSkill
- testSkill
- update-bannerSkill
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.

