ai

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ai is the port for drafting commit messages, branch names and pull-request text. Adapters (Claude Code today, a direct API tomorrow) implement Drafter; prompts and output schemas live here so every adapter behaves the same.

Index

Constants

View Source
const CommitSchema = `` /* 279-byte string literal not displayed */

CommitSchema is the JSON schema for Commit.

View Source
const MaxDiffBytes = 100_000

MaxDiffBytes bounds the diff sent to the model.

View Source
const PRSchema = `` /* 170-byte string literal not displayed */

PRSchema is the JSON schema for PullRequest.

Variables

This section is empty.

Functions

func CommitPrompt

func CommitPrompt(in CommitInput) (instruction, context string)

CommitPrompt renders the instruction and the stdin context for DraftCommit.

func PRPrompt

func PRPrompt(in PRInput) (instruction, context string)

PRPrompt renders the instruction and stdin context for DraftPR.

func TruncateDiff

func TruncateDiff(diff string, maxBytes int) (string, bool)

TruncateDiff cuts a diff at a line boundary near max bytes and reports whether it did.

func ValidateCommit

func ValidateCommit(c Commit) error

ValidateCommit checks a drafted commit for the obvious failure modes.

func ValidatePR

func ValidatePR(p PullRequest) error

ValidatePR checks a drafted pull request.

Types

type Commit

type Commit struct {
	BranchName string `json:"branch"`
	Message    string `json:"message"`
}

Commit is a drafted branch name (without prefix) and commit message.

type CommitInput

type CommitInput struct {
	// Diff is the staged diff, possibly truncated.
	Diff          string
	DiffTruncated bool
	// Message, when set, is used as-is and only a branch name is drafted.
	Message string
	// RecentSubjects are the last trunk commit subjects, for house style.
	RecentSubjects []string
	// BranchPrefix is prepended to the generated name by the caller; the
	// model is told about it so it does not repeat it.
	BranchPrefix string
	// TakenBranches lists existing branch names to avoid.
	TakenBranches []string
	// ExtraPrompt is appended verbatim (git config stack.ai.extraPrompt).
	ExtraPrompt string
}

CommitInput is the context for drafting a branch name and commit message. The caller computes everything; the model never runs git.

type Drafter

type Drafter interface {
	DraftCommit(ctx context.Context, in CommitInput) (Commit, error)
	DraftPR(ctx context.Context, in PRInput) (PullRequest, error)
}

Drafter generates text. Implementations must be safe to call from any goroutine and must honour ctx.

type PRInput

type PRInput struct {
	Branch, Parent string
	Diff           string
	DiffTruncated  bool
	// Commits are the full commit messages on the branch, oldest first.
	Commits        []string
	RecentSubjects []string
	// Template is the repository's PR template, if any.
	Template    string
	ExtraPrompt string
}

PRInput is the context for drafting a pull request title and body.

type PullRequest

type PullRequest struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

PullRequest is a drafted title and body.

Directories

Path Synopsis
Package claudecode implements ai.Drafter with the local Claude Code CLI in headless mode (`claude -p`).
Package claudecode implements ai.Drafter with the local Claude Code CLI in headless mode (`claude -p`).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL