Pmad.Git.CliEmulator.AI
0.2.8
dotnet add package Pmad.Git.CliEmulator.AI --version 0.2.8
NuGet\Install-Package Pmad.Git.CliEmulator.AI -Version 0.2.8
<PackageReference Include="Pmad.Git.CliEmulator.AI" Version="0.2.8" />
<PackageVersion Include="Pmad.Git.CliEmulator.AI" Version="0.2.8" />
<PackageReference Include="Pmad.Git.CliEmulator.AI" />
paket add Pmad.Git.CliEmulator.AI --version 0.2.8
#r "nuget: Pmad.Git.CliEmulator.AI, 0.2.8"
#:package Pmad.Git.CliEmulator.AI@0.2.8
#addin nuget:?package=Pmad.Git.CliEmulator.AI&version=0.2.8
#tool nuget:?package=Pmad.Git.CliEmulator.AI&version=0.2.8
Pmad.Git.CliEmulator.AI
Microsoft.Extensions.AI integration for Pmad.Git.CliEmulator.
Exposes the managed Git CLI emulator as a single git AIFunction that any IChatClient-based agent pipeline can call as a tool — no native git binary required.
Features
- One
gittool, all sub-commands —status,log,diff,show,add,restore,commit,reset,revert,merge,branch,tag,config,remote,ls-tree,rev-parse,cat-file,fetch,pull,push. - Array-args or string-args — pick the variant that best matches the model you're using.
- Safe by default — gated operations (destructive and network operations) are denied automatically unless you supply an
IUserApprovalimplementation. - DI-friendly — one-line
IServiceCollectionregistration viaAddGitCliEmulatorAI. - No native Git dependency — pure managed C#, AOT-compatible via the underlying
Pmad.Git.CliEmulator.
Quick Start
Option A — Extension method on the emulator
using Pmad.Git.CliEmulator;
using Pmad.Git.CliEmulator.AI;
using Microsoft.Extensions.AI;
using var emulator = GitCliEmulator.Open("/path/to/repo");
AIFunction gitTool = emulator.CreateAIFunction();
IChatClient client = new ChatClientBuilder(innerClient)
.UseFunctionInvocation()
.Build();
var response = await client.CompleteAsync(
"What files have changed since the last commit?",
new ChatOptions { Tools = [gitTool] });
Option B — Factory directly
using Pmad.Git.CliEmulator;
using Pmad.Git.CliEmulator.AI;
using var emulator = GitCliEmulator.Open("/path/to/repo");
// Array-args variant (recommended — most models handle JSON arrays well)
AIFunction gitTool = GitAIFunctionFactory.Create(emulator);
// String-args variant (for models that prefer a single string)
AIFunction gitToolStr = GitAIFunctionFactory.CreateFromString(emulator);
Option C — Dependency injection
// Program.cs / Startup.cs
using Pmad.Git.CliEmulator.AI;
using Pmad.Git.RemoteClient;
builder.Services.AddGitCliEmulatorAI(
repositoryPath: "/path/to/repo",
remoteOptions: new GitRemoteClientOptions
{
Credentials = new GitHttpCredentials("pat", Environment.GetEnvironmentVariable("GH_TOKEN")!)
});
// Inject AIFunction (or IEnumerable<AIFunction>) wherever you build your agent:
app.MapGet("/agent", async (AIFunction gitTool, IChatClient chat) =>
{
var options = new ChatOptions { Tools = [gitTool] };
var response = await chat
.AsBuilder().UseFunctionInvocation().Build()
.CompleteAsync("Summarise recent commits", options);
return response.Message.Text;
});
Approval Gates
By default, gated operations (destructive operations like reset --hard or network operations like push) are denied (DenyApproval.Instance) to protect repositories from unintended AI modifications. To permit gated operations or implement custom approval logic, provide an IUserApproval implementation (or AutoApproval.Instance to approve all operations) to any of the factory or extension methods:
IUserApproval myApproval = new MyApproval(CancellationToken.None);
AIFunction gitTool = emulator.CreateAIFunction(myApproval);
// or
AIFunction gitTool = GitAIFunctionFactory.Create(emulator, myApproval);
Package
| Package | NuGet |
|---|---|
Pmad.Git.CliEmulator.AI |
Dependencies
| Package | Purpose |
|---|---|
Pmad.Git.CliEmulator |
Core Git CLI emulator |
Microsoft.Extensions.AI.Abstractions |
AIFunction, AIFunctionFactory |
Microsoft.Extensions.DependencyInjection.Abstractions |
IServiceCollection extensions |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.AI.Abstractions (>= 10.10.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Pmad.Git.CliEmulator (>= 0.2.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.