Skip to content

Repository files navigation

OAICLI

A .NET CLI that uses the OpenAI Chat Completions API (gpt-4o) to generate unit tests and XML documentation comments for C# code in the current solution.

License GitHub commit activity GitHub contributors GitHub Actions Workflow Status

What it does

OAICLI scans the current .sln and .csproj files, gathers C# source files, and posts them to OpenAI along with a structured prompt and response schema. The model returns JSON containing a summary, file edits, and a commit message; the tool then displays the diff and (optionally) applies the changes.

Command Status Purpose
test (default) available Generate MSTest unit tests for the current solution.
document available Add or improve XML doc comments on C# files.
code-review stubbed Source exists; the file-diff and atomic-write logic is currently commented out.

Tech

  • Built on ktsu.Sdk.App (multi-targeted from netstandard2.0 through net10.0).
  • CLI uses Spectre.Console.Cli with CommandLineParser for option parsing, plus Spectre's Json and ImageSharp extensions for rich console output.
  • Calls the OpenAI HTTP API directly (POST https://api.openai.com/v1/chat/completions) — does not depend on any OpenAI SDK.
  • The expected response schema is generated via NJsonSchema.
  • Hard-codes the gpt-4o model.

Auth

On first run the tool prompts for an OpenAI API key and stores it in the operating system's secret store via ktsu.CredentialCache — Windows Credential Manager, macOS Keychain, or libsecret (Secret Service) on Linux. Subsequent runs reuse the stored key.

A key saved by an earlier version, which kept it in plaintext in ktsu.AppDataStorage's JSON file (typically %APPDATA%\ktsu\OAICLI on Windows), is migrated into the secret store on the next run and blanked in the old file. Nothing needs to be re-entered.

If no secret store is available — most often a Linux host with no Secret Service provider installed and unlocked, which is common over SSH and in containers — the tool reports that and stops. It does not fall back to writing the key to a plain file.

Installation

git clone <repo>
cd OAICLI
dotnet build

Usage

# Generate tests for the current solution (default)
OAICLI

# Generate XML doc comments for the current solution
OAICLI document

# Provide additional context files
OAICLI test --context path/to/helper.cs path/to/extension.cs

# Skip the diff preview prompt
OAICLI test --force
Option Long form Effect
-c --context Extra context file paths to include with the request.
-f --force Skip the diff preview and accept the AI's edits.

License

MIT — see LICENSE.md.

About

A .NET command-line tool that uses the OpenAI Chat Completions API to generate MSTest unit tests and XML documentation comments for C# code in the current solution. Scans the solution and project files, posts the gathered sources alongside a structured response schema, then presents the returned diff and optionally applies the edits.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages