Agents
-
This repository is a Swift Package (see
Package.swift). The fileAGENTS.mddocuments how automated agents should build, test, lint, and follow repository style conventions. -
Location:
/Users/linhey/Desktop/swift-git/AGENTS.md -
Primary commands
- Build (debug):
swift build- Build (release):
swift build -c release- Run tests (all):
swift test- Run a single test by name (recommended):
# Filter matches test case and/or function name. Examples:
swift test --filter Test.test_format_date
swift test --filter test_format_date- Run a single test target (if multiple test targets exist):
swift test --package-path . --filter <TestName>-
Run a single test file under Xcode (if you open the package in Xcode): select the test method and press the test button or run
Product → Testfor the scheme. -
Formatting / Linting
- This repository does not commit a linter or formatter configuration (no
.swiftlint.ymlor.swift-formatfile found at the repository root). Recommended tools (optional):- SwiftLint:
brew install swiftlintthenswiftlint lint(orswiftlint autocorrect). - swift-format: follow Apple or community formatter and add a
.swift-formatconfig if you want automated formatting.
- SwiftLint:
- This repository does not commit a linter or formatter configuration (no
-
If you add a formatter/linter, update this document and add its config to the repo root.
- This repository now includes minimal configuration examples:
.swiftformat— basic formatting rules used byswiftformat/community tools..swiftlint.yml— basic SwiftLint configuration. These are small defaults; adjust rules to taste.
- This repository now includes minimal configuration examples:
-
Common CI commands
- Build + test (fast):
swift test --enable-test-discovery - Build for release in CI:
swift build -c release --disable-sandbox(use sandbox flags per your CI environment)
- Build + test (fast):
-
How to run tests with verbose output
- Use
swift test --show-test-coverage(when supported) or run tests in Xcode for detailed logs.
- Use
-
Files to know
Package.swift— Swift Package manifestSources/SwiftGit— main library sourceTests/SwiftGitTests/Test.swift— example test
-
Cursor / Copilot rules
- No
.cursoror.cursorrulesdirectory found in repository root. - No Copilot instructions file found at
.github/copilot-instructions.md. - If you add Cursor/Copilot rules, place them in
.cursor/rules/and reference them here.
- No
-
Skills
- If your agent supports skills, follow the
SKILL.mdinstructions for any skill you use. - This repo does not define repo-specific skills; rely on your toolchain's skill list when available.
- If your agent supports skills, follow the
-
Code style guidelines
-
Imports
- Group imports into three sections (top to bottom): system (Foundation, Dispatch), third-party (e.g.,
STFilePath), and internal modules. Leave a single blank line between groups. - Use only the modules you need; avoid
import Foundationunless required by APIs used in the file.
- Group imports into three sections (top to bottom): system (Foundation, Dispatch), third-party (e.g.,
-
File headers and structure
- Keep files small and focused: one top-level type or tightly related small types per file.
- Preserve the existing brief file header comments used in this repository (single-line with creation metadata is acceptable but not required).
-
Formatting
- Follow Swift API Design Guidelines for spacing and naming.
- Use 4-space indentation for braces-based blocks. Keep line length under ~120 columns when practical.
- Place opening brace on same line as declaration:
func foo() {.
-
Naming conventions
- Types (struct/enum/class/protocol): UpperCamelCase (e.g.,
Repository,GitError). - Functions and variables: lowerCamelCase (e.g.,
setupProcess,terminationHandler). - Constants:
letwith lowerCamelCase; use descriptive names. - Errors: define
enum ...: Errorwith cases in lowerCamelCase. If exposing public errors, conform toLocalizedErrorand provideerrorDescriptionand a numericcodeif helpful (seeSources/SwiftGit/Custom/GitError.swift).
- Types (struct/enum/class/protocol): UpperCamelCase (e.g.,
-
Types & API design
- Prefer value types (struct/enum) for small, thread-safe types. Use
classonly when reference semantics are required. - Keep public API surface minimal and documented with doc comments (
///). - Use
@availableattributes consistently when providing platform‑specific APIs (see#if os(macOS)and@available(macOS 11, *)blocks inShell.swift).
- Prefer value types (struct/enum) for small, thread-safe types. Use
-
Concurrency
- Prefer async/await for new asynchronous code on supported platforms. Provide Combine publishers only when the codebase already uses Combine (as in
Shellfor backwards compatibility). - Keep Task cancellation propagation explicit; check
Task.checkCancellation()orTask.isCancelledwhere long-running work occurs.
- Prefer async/await for new asynchronous code on supported platforms. Provide Combine publishers only when the codebase already uses Combine (as in
-
Error handling
- Use typed Error enums rather than opaque strings when possible (see
GitErrorinSources/SwiftGit/Custom/GitError.swift). - When wrapping underlying errors, preserve the underlying
Errorvalue (e.g.,.other(Error)) and propagate useful contextual information usingLocalizedErrorconformance. - Avoid
.forceTryortry!in production code; if atry!is used in tests or initialization with an invariant, add a comment explaining why it is safe.
- Use typed Error enums rather than opaque strings when possible (see
-
Optionals
- Minimize force-unwrapping (
!). Preferguard letorif letto safely unwrap. - When returning optional values from APIs, document why
nilmay be returned.
- Minimize force-unwrapping (
-
Logging & prints
- Avoid
print()in library-level code. Useos_logor a configurable logger for library clients. Tests may useprintfor debugging but remove debug prints before committing.
- Avoid
-
Process & Shell usage
- Centralize process execution code (the repository already has
Shellutilities). Keep behavior consistent: capture both stdout and stderr, includecurrentDirectoryin error messages, and return typed errors (seeShell.result). - Do not duplicate process setup logic — add new functionality to
Shell.Instanceor small helpers.
- Centralize process execution code (the repository already has
-
Combine & Publishers
- When exposing Combine publishers, ensure they are erased with
.eraseToAnyPublisher()at the boundary. - Use
PassthroughSubjectfor ephemeral streams andCurrentValueSubjectfor stateful values.
- When exposing Combine publishers, ensure they are erased with
-
Tests
- Tests live in
Tests/SwiftGitTests. Use theTestingpackage conventions already present (seeTests/SwiftGitTests/Test.swift). - Prefer
asynctest methods for async code. Use@Test/XCTest-style attributes according to your test dependency. - Keep tests deterministic: avoid network I/O and environment-specific dependencies. Use fixtures or mock file system/state.
- Tests live in
-
Documentation
- Document public APIs with
///comments. Include short examples when it helps explain usage.
- Document public APIs with
-
PR / Commit notes for agents
- When creating changes, keep commits small and focused; commit messages should be 1–2 lines explaining the "why" (not a line-by-line description).
- Do not run destructive git commands. Avoid force pushes to protected branches.
-
When you are blocked
- If a change is ambiguous or may affect users (public API, version bump, or security), add a short issue or ask a human reviewer.
-
Adding linters / rules
- If you add
.swift-formator.swiftlint.yml, updateAGENTS.mdimmediately with the command to run them and recommended pre-commit hooks.
- If you add
-
Contact & context
- Primary language: Swift. Platform: macOS (Package.swift declares macOS v12 minimum).
- The repo bundles a git instance at
Sources/SwiftGit/Resource/git-instance.bundle— agents should not modify the bundle contents unless explicitly intended.
If you want, I can also:
- Add a basic
.swift-formatconfig and aswiftformatcommand in CI. - Add a minimal
.swiftlint.ymlwith cores rules and an example pre-commit hook.