Skip to content

Commit 10ed0a3

Browse files
committed
feat: Add swift-git skill definition and comprehensive API reference documentation, including Chinese localization.
1 parent ce63853 commit 10ed0a3

46 files changed

Lines changed: 2567 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.skills/swift-git/SKILL.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: "swift-git"
3+
description: "Repository-focused skill for building, testing, and agent-safe operations in the SwiftGit repository. Use when performing build/test tasks, running single tests, or when an automated agent needs to follow repository agent rules and safe commands."
4+
---
5+
6+
# swift-git skill
7+
8+
Purpose
9+
- Provide concise, actionable instructions and examples for automated agents and humans working with this repository.
10+
- Expose the small set of repository-specific commands and agent rules an automated worker needs so the runtime can make safe decisions without loading large docs.
11+
12+
When to use this skill (trigger examples)
13+
- "Build the package"
14+
- "Run tests"
15+
- "Run a single test"
16+
- "Where are the build/test commands"
17+
- "What agent rules should I follow for commits and CI"
18+
19+
Quick commands (do not execute without user approval)
20+
- Build (debug):
21+
- swift build
22+
- Build (release):
23+
- swift build -c release
24+
- Run full tests:
25+
- swift test
26+
- Run a single test (filter by name):
27+
- swift test --filter ParseTests.testChangedEntryIndex_valid
28+
- swift test --filter test_format_date
29+
30+
Repository constraints (MUST follow)
31+
- Do NOT create commits or push to remote on behalf of a user unless explicitly authorized.
32+
- Do NOT modify the embedded git bundle at Sources/SwiftGit/Resource/git-instance.bundle.
33+
- Avoid adding or enforcing new lint/format rules without updating AGENTS.md and CI configuration.
34+
35+
Agent safety rules (short)
36+
- Prefer array-based process invocations in code over shell-escaped string commands to avoid escaping bugs.
37+
- Prefer existing libraries and small focused changes vs large refactors.
38+
- When making multi-step changes, create an explicit TODO plan and surface it before editing.
39+
40+
References
41+
- See references/AGENTS.md for a concise, agent-focused summary of AGENTS.md and repository tooling.
42+
43+
Examples (do not auto-run)
44+
- "I want to run the test suite locally": use `swift test` from repository root.
45+
- "Run a single test": use `swift test --filter <TestName>` as shown above.
46+
- "Check package manifest": open Package.swift at repository root.
47+
48+
Packaging the skill
49+
- To package this skill (manual step), follow your environment's packaging script. Example: `scripts/package_skill.py swift-git.skill` (if package exists in your environment).
50+
51+
FAQ
52+
- Q: Should an agent commit changes it makes?
53+
- A: No. Only stage files locally and present a diff; commit only if the user explicitly asks.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This file is a concise, agent-focused summary of the repository AGENTS.md tailored for automated workers.
2+
3+
Core commands
4+
- Build (debug): swift build
5+
- Build (release): swift build -c release
6+
- Run all tests: swift test
7+
- Run a single test: swift test --filter <TestName>
8+
9+
Agent working rules (must follow)
10+
- NEVER commit or push without explicit user permission.
11+
- NEVER modify the embedded git bundle under Sources/SwiftGit/Resource/git-instance.bundle.
12+
- When creating commits, follow repository commit message style: short 1-2 line message that explains the why.
13+
- If adding linters or formatters, update AGENTS.md and CI configs accordingly.
14+
15+
Test & CI notes
16+
- CI uses GitHub Actions (.github/workflows/ci.yml). Prefer macos-latest runners.
17+
- Integration tests prefer the embedded git instance and fall back to system git.
18+
19+
File locations
20+
- Package manifest: Package.swift
21+
- Main sources: Sources/SwiftGit/
22+
- Tests: Tests/SwiftGitTests/
23+
24+
Helpful patterns
25+
- Use Shell utilities present in Sources/SwiftGit/Custom/Shell.swift for centralized process execution.
26+
- Prefer array-based arguments when invoking Shell helpers (avoid building a single shell string).
27+
28+
Contact
29+
- Open an issue with commands and repository state when blocked.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# SwiftGit public API inventory
2+
3+
This document catalogs the public API surface of the SwiftGit package and provides focused documentation and usage examples for automated agents and human readers. It is intended to be consumed by agents to generate actionable SKILL content for each API area.
4+
5+
Structure
6+
- Classes & types: short descriptions and top-level public members
7+
- Models: commonly used value types and their important properties
8+
- Options: ExpressibleByStringLiteral option types used as argument helpers
9+
- Commands: repository/command helpers exposed as public extensions
10+
- Tests: reference to tests that target the public API
11+
12+
Primary public types
13+
14+
1) Git (class)
15+
- Location: Sources/SwiftGit/Custom/Git.swift
16+
- Summary: High-level entrypoint for running git commands via the package. Holds a GitEnvironment and a Shell.Instance for process execution.
17+
- Important public members (selection):
18+
- public static var shared: Git { get throws }
19+
- public init(environment: GitEnvironment)
20+
- public func data(_ commands: [String], context: Shell.Context? = nil) async throws -> Data
21+
- public func run(_ commands: [String], context: Shell.Context? = nil) async throws -> String
22+
- public func run(_ cmd: String, context: Shell.Context? = nil) async throws -> String
23+
- public func data(_ commands: [String], context: Shell.Context? = nil) throws -> Data
24+
- public func run(_ commands: [String], context: Shell.Context? = nil) throws -> String
25+
- public func repository(at url: URL) -> Repository
26+
- public func repository(at path: String) -> Repository
27+
28+
2) GitEnvironment (class & nested types)
29+
- Location: Sources/SwiftGit/Custom/GitEnvironment.swift
30+
- Summary: Represents a configured git runtime (embedded, system, or custom). Encapsulates resource (executable), environment variables, and triggers.
31+
- Important public members:
32+
- public enum Style { case embed, system, custom(_ url: URL), auto }
33+
- public struct Resource { public let executableURL: URL; public let envExecPath: String? }
34+
- public struct Variable { factory helpers: execPath(_:), home(_:), prefix(_:), configNoSystem(_:), etc. }
35+
- public init(resource: Resource, variables: [Variable], triggers: [GitTrigger])
36+
- public static var shared: GitEnvironment { get }
37+
38+
3) Repository (struct)
39+
- Location: Sources/SwiftGit/Custom/Repository.swift
40+
- Summary: Convenience repository-scoped helpers backed by a Git instance. Provides many sub-APIs for common git workflows.
41+
- Important public members (selection):
42+
- public init(git: Git, url: URL)
43+
- public init(git: Git, path: String)
44+
- public extension Repository { many repository helpers live in extensions (clone, commit, push, status, tag, stash, etc.) }
45+
46+
4) Shell (structs & Instance)
47+
- Location: Sources/SwiftGit/Custom/Shell.swift
48+
- Summary: Centralized process execution utilities (sync/async + Combine publishers). Prefer these helpers when invoking git.
49+
- Important public types & members:
50+
- public struct Context { public var environment: [String: String]; public var currentDirectory: URL?; public let standardOutput: PassthroughSubject<Data, Never>? }
51+
- public struct Arguments / ShellArguments
52+
- public struct Instance { public var changedArgsBeforeRun: ((_ args: inout Arguments) -> Void)?; public func data(_ args: Shell.Arguments) async throws -> Data; public func string(_ args: Shell.Arguments) async throws -> String }
53+
- convenience static helpers: Shell.zsh(...), Shell.data(...), Shell.string(...)
54+
55+
5) GitTrigger (struct)
56+
- Location: Sources/SwiftGit/Custom/GitTrigger.swift
57+
- Summary: Small callback/event primitive used by GitEnvironment to trigger hooks on events.
58+
- Important public members:
59+
- public enum Event: Int { case beforeRun, afterRun }
60+
- public struct Content { public let commands: [String]; public let data: Data }
61+
- public init(on event: Event, action: @escaping (_ result: Result<Content, Error>) -> Void)
62+
- public static func failure(on:event, action: ...) and success(on:event, action: ...)
63+
64+
Models (examples)
65+
- GitStatus (Sources/SwiftGit/Custom/models/GitStatus.swift): public struct GitStatus with properties branch, changed, renamedCopied, unmerged, untracked. Several nested types represent entries and styles.
66+
- Commit / Commit enums: Sources/SwiftGit/Custom/models/Commit.swift
67+
- Reference types: Sources/SwiftGit/Custom/models/Reference.swift (protocol ReferenceType, structs Branch, Tag)
68+
- Pathspec: ExpressibleByStringLiteral helper, value wrapper
69+
70+
Options
71+
- Many option types are defined as small structs conforming to ExpressibleByStringLiteral for convenient API composition. Examples:
72+
- AddOptions, ResetOptions, CloneOptions, CommitOptions, PushOptions, FetchOptions, StatusOptions, etc. (see Sources/SwiftGit/options/)
73+
74+
Commands & repository extensions
75+
- Most git subcommands are exposed as public extensions on Git or Repository under Sources/SwiftGit/Custom/commands/*. Each file shapes a coherent sub-API (clone, commit, push, fetch, log, status, tag, stash, etc.).
76+
77+
Tests that reference public APIs
78+
- Tests live under Tests/SwiftGitTests. Key files that exercise public APIs include:
79+
- Tests/SwiftGitTests/IntegrationTests.swift
80+
- Tests/SwiftGitTests/ParseTests.swift
81+
- Tests/SwiftGitTests/CloneCommandTests.swift
82+
- Tests/SwiftGitTests/ShowCommitResultTests.swift
83+
84+
How this inventory will be used
85+
- The next step is to generate per-API skill documentation files that include:
86+
- The declaration/signature
87+
- Short description
88+
- Examples of usage (non-executable snippets)
89+
- Tests referencing the API
90+
91+
Follow-up files to generate (I will create when you approve):
92+
- references/apis/Git.md
93+
- references/apis/GitEnvironment.md
94+
- references/apis/Repository.md
95+
- references/apis/Shell.md
96+
- references/apis/GitTrigger.md
97+
- references/apis/Models.md
98+
- references/apis/Options.md
99+
- references/apis/Commands.md
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Commands
2+
3+
This section maps the command helper files in Sources/SwiftGit/Custom/commands/ to high-level responsibilities. Each file typically exposes public extensions on Git or Repository and associated option types.
4+
5+
Files & purpose (selection)
6+
- git-commands-clone.swift — clone helpers and CloneOptions
7+
- git-commands-commit.swift — commit helpers and CommitOptions
8+
- git-commands-status.swift — status helpers and StatusOptions
9+
- git-commands-log.swift — log helpers and LogOptions
10+
- git-commands-push.swift — push helpers and PushOptions
11+
- git-commands-fetch.swift — fetch helpers
12+
- git-commands-tag.swift — tag helpers
13+
- git-commands-stash.swift — stash helpers
14+
15+
Notes for agents
16+
- For each command helper, open the corresponding file to extract exact function signatures and examples. When in doubt, prefer the explicit functions that accept typed option structs.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Git
2+
3+
Location: Sources/SwiftGit/Custom/Git.swift
4+
5+
Public declaration highlights
6+
- public class Git
7+
- public static var shared: Git { get throws }
8+
- public init(environment: GitEnvironment)
9+
- public func data(_ commands: [String], context: Shell.Context? = nil) async throws -> Data
10+
- public func run(_ commands: [String], context: Shell.Context? = nil) async throws -> String
11+
- public func run(_ cmd: String, context: Shell.Context? = nil) async throws -> String
12+
- public func data(_ commands: [String], context: Shell.Context? = nil) throws -> Data
13+
- public func run(_ commands: [String], context: Shell.Context? = nil) throws -> String
14+
- public func run(_ cmd: String, context: Shell.Context? = nil) throws -> String
15+
- public func repository(at url: URL) -> Repository
16+
- public func repository(at path: String) -> Repository
17+
18+
Summary
19+
The Git class is the high-level entrypoint for running Git commands. It wraps a GitEnvironment (which selects an embedded or system git) and a Shell.Instance that performs the actual process execution. Use Git for programmatic access to git operations in this package.
20+
21+
Usage examples
22+
- Async run example:
23+
24+
let git = try Git(environment: .shared)
25+
let output = try await git.run(["status", "--porcelain=v2"]) // String
26+
27+
- Sync data example (throws):
28+
29+
let data = try git.data(["rev-parse", "HEAD"]) // Data
30+
31+
Notes for agents
32+
- Prefer the array-based overloads ([String]) to avoid shell-escaping issues.
33+
- Do not modify Git.shared unless explicitly requested by the repository maintainer; creating a new Git(environment:) is preferred for test isolation.
34+
35+
Tests that reference Git
36+
- Tests/SwiftGitTests/* includes integration tests that create Git/GitEnvironment instances and exercise repository workflows. See IntegrationTests.swift and RepositoryRunTests.swift.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# GitEnvironment
2+
3+
Location: Sources/SwiftGit/Custom/GitEnvironment.swift
4+
5+
Public declaration highlights
6+
- public class GitEnvironment
7+
- public enum Style { case embed, system, custom(_ url: URL), auto }
8+
- public struct Resource { public let executableURL: URL; public let envExecPath: String? }
9+
- public struct Variable { factory helpers: execPath(_:), home(_:), prefix(_:), configNoSystem(_:), etc. }
10+
- public init(resource: Resource, variables: [Variable], triggers: [GitTrigger])
11+
- public static var shared: GitEnvironment { get }
12+
13+
Summary
14+
Encapsulates how the library locates and configures a git binary, including an embedded git bundle or system git. Variables allow customizing environment variables such as GIT_EXEC_PATH and HOME.
15+
16+
Usage
17+
18+
let env = try GitEnvironment(resource: .init(executableURL: url), variables: [], triggers: [])
19+
let git = Git(environment: env)
20+
21+
Notes for agents
22+
- When tests or integration code need predictable behavior, prefer explicitly constructed GitEnvironment instances over .shared.
23+
24+
Tests referencing GitEnvironment
25+
- GitEnvironmentTests.swift and GitEnvironmentInitTests.swift
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# GitTrigger
2+
3+
Location: Sources/SwiftGit/Custom/GitTrigger.swift
4+
5+
Public declaration highlights
6+
- public struct GitTrigger
7+
- public enum Event: Int { case beforeRun, afterRun }
8+
- public struct Content { public let commands: [String]; public let data: Data }
9+
- public init(on event: Event, action: @escaping (_ result: Result<Content, Error>) -> Void)
10+
- public static func failure(on:event, action: ...) and success(on:event, action: ...)
11+
12+
Summary
13+
Small event/callback primitive used by GitEnvironment to invoke actions before or after certain events. Useful for logging, telemetry, or validation hooks.
14+
15+
Usage example
16+
17+
let trigger = GitTrigger(on: .beforeRun) { result in
18+
switch result { case .success(let content): print(content.commands) case .failure(let err): print(err) }
19+
}
20+
21+
Notes for agents
22+
- When constructing GitEnvironment for tests, pass triggers to observe command execution events.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Models
2+
3+
This page summarizes commonly used models exposed by the package.
4+
5+
GitStatus
6+
- Location: Sources/SwiftGit/Custom/models/GitStatus.swift
7+
- public struct GitStatus: Equatable with properties branch, changed, renamedCopied, unmerged, untracked and nested entry types.
8+
9+
Commit & User models
10+
- Sources/SwiftGit/Custom/models/Commit.swift
11+
- Sources/SwiftGit/Custom/results/LogResult.swift
12+
13+
Reference types
14+
- Sources/SwiftGit/Custom/models/Reference.swift contains ReferenceType protocol and concrete Branch/Tag types for strongly-typed references.
15+
16+
Pathspec
17+
- Sources/SwiftGit/Custom/models/Pathspec.swift — ExpressibleByStringLiteral helper for pathspecs.
18+
19+
Notes for agents
20+
- Models are value types and safe to pass around. Prefer using them in examples rather than raw strings when demonstrating APIs.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Options
2+
3+
The repository defines many small option types used to compose git command arguments. All are in Sources/SwiftGit/options/ and most conform to ExpressibleByStringLiteral for convenient construction.
4+
5+
Examples
6+
- CloneOptions, CommitOptions, PushOptions, FetchOptions, StatusOptions, ResetOptions, AddOptions, etc.
7+
8+
Usage example
9+
10+
try await repo.log(options: .init("--oneline"))
11+
12+
Notes for agents
13+
- These option types are lightweight wrappers. When generating examples, prefer to show both literal string usage and typed usage (e.g., .message("msg")).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Repository
2+
3+
Location: Sources/SwiftGit/Custom/Repository.swift
4+
5+
Public declaration highlights
6+
- public struct Repository
7+
- public init(git: Git, url: URL)
8+
- public init(git: Git, path: String)
9+
- Many repository-scoped command helpers are defined as public extensions across Sources/SwiftGit/Custom/commands/*. These include clone, commit, push, status, tag, stash, fetch, pull, merge, etc.
10+
11+
Summary
12+
Repository is a lightweight wrapper that provides convenience methods executing git commands within a repository directory using an associated Git instance.
13+
14+
Usage example
15+
16+
let git = try Git(environment: .shared)
17+
let repo = git.repository(at: "/path/to/repo")
18+
try await repo.commit("message", options: .init())
19+
20+
Notes for agents
21+
- Look for specific helper files under Sources/SwiftGit/Custom/commands/ to find detailed signatures and option types for each command.
22+
23+
Tests
24+
- CloneCommandTests, IntegrationTests, and RepositoryRunTests contain examples that exercise Repository helpers.

0 commit comments

Comments
 (0)