agentleFS
molayabmolayab/swift-ai-provider-kit/.github/copilot-instructions.md

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
  1. Very specific:

    Use actor for all mutable shared state.

    line 12
  2. Very specific:

    Use async/await and structured concurrency (withThrowingTaskGroup).

    line 13
  3. Very specific:

    Every provider must follow the mapper pattern: a dedicated XRequestMapper and XResponseMapper.

    line 24
  4. Very specific:

    Prefer value types (struct, enum) over reference types unless actor semantics or identity are required.

    line 33
  5. Very specific:

    Avoid force unwraps (!) and try!

    line 34
  6. Distinctive:

    No magic strings or numbers.

    line 36
  7. Distinctive:

    All tests follow given / when / then with section comments.

    line 44

≈ “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.

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

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 actor for all mutable shared state. Prefer actor over class + locks.
  • Use async/await and structured concurrency (withThrowingTaskGroup). Flag any GCD, DispatchQueue, or callback-based patterns.
  • final class is acceptable only when the type holds exclusively Sendable dependencies and has no mutable state after init.
  • @unchecked Sendable must have an accompanying comment explaining why it is safe.
  • Flag nonisolated on actor methods unless the method only reads let properties.

Architecture Rules

  • AIClient is the only coordinator. No new type should import details of a specific provider.
  • New providers must conform to AIProvider (or AIStreamableProvider for streaming support). No changes to AIClient or core types are required or acceptable.
  • Every provider must follow the mapper pattern: a dedicated XRequestMapper and XResponseMapper. No mapping logic inside the provider class itself.
  • ContentBlock is the universal content currency. Providers must map to/from it; they must not leak provider-specific types into AIProviderKit.
  • JSONValue is the required type for all tool inputs and outputs. Flag any use of Any, [String: Any], or AnyCodable.
  • Registries (ToolRegistry, SkillRegistry, RecipeRegistry) are actors. Access must be awaited; 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 (!) and try!. Use guard let or propagate errors.
  • Errors must conform to the project's AIError type or a clearly named domain error. Avoid bare throw 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.
  • AIClient tests use MockAIProvider or SequentialMockProvider for multi-turn scenarios.
  • Integration tests (under Sources/IntegrationTests/) require ANTHROPIC_API_KEY and 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.md or Documentation/UseCases.md.
  • New provider walkthroughs go in Documentation/AddingAProvider.md.

Security

  • API keys must never be hardcoded. Use AuthorizationProvider injection.
  • Flag any print() or NSLog() calls that could leak tokens or user data. Use AILogger instead.
  • HTTP requests must go through HTTPClient protocol — never call URLSession directly in provider or mapper code.

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.