Documentation
¶
Overview ¶
Package forge provides a pluggable code forge interface for issue, pull request, and code review management. Each forge provider (GitHub, Gitea, GitLab) implements the ForgeProvider interface and is registered by name with the Manager. The agent accesses forge operations through tool handlers defined in Tools.
Index ¶
- type AccountConfig
- type ChangedFile
- type CheckRun
- type Comment
- type Commit
- type Config
- type ContextProvider
- type ForgeProvider
- type GitHub
- func (g *GitHub) AddComment(ctx context.Context, repo string, number int, body string) (*Comment, error)
- func (g *GitHub) AddReaction(ctx context.Context, repo string, number int, commentID int64, emoji string) error
- func (g *GitHub) AddReviewComment(ctx context.Context, repo string, number int, comment *ReviewComment) (*ReviewComment, error)
- func (g *GitHub) CreateIssue(ctx context.Context, repo string, issue *Issue) (*Issue, error)
- func (g *GitHub) GetIssue(ctx context.Context, repo string, number int) (*Issue, error)
- func (g *GitHub) GetPR(ctx context.Context, repo string, number int) (*PullRequest, error)
- func (g *GitHub) GetPRDiff(ctx context.Context, repo string, number int) (string, error)
- func (g *GitHub) GetPRFiles(ctx context.Context, repo string, number int) ([]*ChangedFile, error)
- func (g *GitHub) ListChecks(ctx context.Context, repo string, number int) ([]*CheckRun, error)
- func (g *GitHub) ListIssues(ctx context.Context, repo string, opts *ListOptions) ([]*Issue, error)
- func (g *GitHub) ListPRCommits(ctx context.Context, repo string, number int) ([]*Commit, error)
- func (g *GitHub) ListPRReviews(ctx context.Context, repo string, number int) ([]*Review, error)
- func (g *GitHub) ListPRs(ctx context.Context, repo string, opts *ListOptions) ([]*PullRequest, error)
- func (g *GitHub) MergePR(ctx context.Context, repo string, number int, opts *MergeOptions) (*MergeResult, error)
- func (g *GitHub) Name() string
- func (g *GitHub) RequestReview(ctx context.Context, repo string, number int, reviewers []string) error
- func (g *GitHub) Search(ctx context.Context, query string, kind SearchKind, limit int) ([]SearchResult, error)
- func (g *GitHub) SubmitReview(ctx context.Context, repo string, number int, review *ReviewSubmission) (*Review, error)
- func (g *GitHub) UpdateIssue(ctx context.Context, repo string, number int, update *IssueUpdate) (*Issue, error)
- type Issue
- type IssueUpdate
- type ListOptions
- type Manager
- type MergeOptions
- type MergeResult
- type Operation
- type OperationLog
- type PullRequest
- type Review
- type ReviewComment
- type ReviewSubmission
- type SearchKind
- type SearchResult
- type Tools
- func (t *Tools) HandleIssueComment(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleIssueCreate(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleIssueGet(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleIssueList(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleIssueUpdate(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRChecks(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRCommits(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRDiff(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRFiles(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRGet(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRList(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRMerge(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRReview(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRReviewComment(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandlePRReviews(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleReact(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleRequestReview(ctx context.Context, args map[string]any) (string, error)
- func (t *Tools) HandleSearch(ctx context.Context, args map[string]any) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountConfig ¶
type AccountConfig struct {
// Name is a short identifier (e.g., "github-primary").
Name string `yaml:"name"`
// Provider selects the forge backend: "github" or "gitea".
Provider string `yaml:"provider"`
// Token is the API authentication token.
Token string `yaml:"token"`
// Owner is the default repository owner for unqualified repo references.
Owner string `yaml:"owner"`
// Username is the forge username for commit attribution.
Username string `yaml:"username"`
// URL is the API base URL. Required for gitea. Optional for GitHub
// (defaults to https://api.github.com).
URL string `yaml:"url"`
}
AccountConfig describes a single forge account.
type ChangedFile ¶
type ChangedFile struct {
// Filename is the path of the changed file.
Filename string
// Status describes the change type: "added", "modified", "removed",
// or "renamed".
Status string
// Additions is the number of lines added in this file.
Additions int
// Deletions is the number of lines removed in this file.
Deletions int
// Patch is the unified diff patch for this file, if available.
Patch string
}
ChangedFile represents a file changed in a pull request.
type CheckRun ¶
type CheckRun struct {
// Name is the check run name (e.g., "CI / lint").
Name string
// Status is the check lifecycle: "queued", "in_progress", or
// "completed".
Status string
// Conclusion is the outcome when completed: "success", "failure",
// "neutral", "cancelled", "skipped", "timed_out", or
// "action_required".
Conclusion string
// StartedAt is when the check run started, if available.
StartedAt *time.Time
// CompletedAt is when the check run finished, if available.
CompletedAt *time.Time
// DetailsURL links to the full check run output.
DetailsURL string
}
CheckRun represents a CI check run on a pull request.
type Comment ¶
type Comment struct {
// ID is the forge-assigned comment identifier.
ID int64
// Body is the comment text in markdown.
Body string
// Author is the username who posted the comment.
Author string
// URL is the web URL for the comment.
URL string
// CreatedAt is when the comment was posted.
CreatedAt time.Time
}
Comment represents a comment on an issue or pull request.
type Commit ¶
type Commit struct {
// SHA is the abbreviated commit hash (typically 7 characters).
SHA string
// Message is the full commit message.
Message string
// Author is the commit author name.
Author string
// Date is when the commit was authored.
Date time.Time
}
Commit represents a single commit in a pull request.
type Config ¶
type Config struct {
Accounts []AccountConfig `yaml:"accounts"`
}
Config holds all forge account configurations.
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults fills in missing optional fields with sensible values.
func (Config) Configured ¶
Configured reports whether at least one forge account is configured with a provider and token.
type ContextProvider ¶ added in v0.8.0
type ContextProvider struct {
// contains filtered or unexported fields
}
ContextProvider injects forge account configuration and recent operations into the system prompt. It implements both agent.ContextProvider (for legacy composite wiring) and agent.TagContextProvider (for tag-gated injection) via structural typing.
When an OperationLog is provided, the context is dynamic — each call to TagContext includes the latest operation history with delta-annotated timestamps.
func NewContextProvider ¶ added in v0.8.0
func NewContextProvider(mgr *Manager, opLog *OperationLog) *ContextProvider
NewContextProvider creates a forge context provider. When opLog is non-nil, recent operations are included in the context each turn.
func (*ContextProvider) GetContext ¶ added in v0.8.0
GetContext returns the forge context block. Implements agent.ContextProvider.
func (*ContextProvider) TagContext ¶ added in v0.9.1
func (p *ContextProvider) TagContext(_ context.Context) (string, error)
TagContext returns the forge context block for tag-gated injection. Implements agent.TagContextProvider.
type ForgeProvider ¶
type ForgeProvider interface {
// Name returns the provider identifier (e.g., "github", "gitea").
Name() string
// CreateIssue creates a new issue and returns it with the
// server-assigned number and URL.
CreateIssue(ctx context.Context, repo string, issue *Issue) (*Issue, error)
// UpdateIssue applies a partial update to an existing issue.
// Only non-nil fields in the update are changed.
UpdateIssue(ctx context.Context, repo string, number int, update *IssueUpdate) (*Issue, error)
// GetIssue retrieves a single issue by number.
GetIssue(ctx context.Context, repo string, number int) (*Issue, error)
// ListIssues returns issues matching the given filters.
ListIssues(ctx context.Context, repo string, opts *ListOptions) ([]*Issue, error)
// AddComment posts a comment on an issue or pull request.
AddComment(ctx context.Context, repo string, number int, body string) (*Comment, error)
// ListPRs returns pull requests matching the given filters.
ListPRs(ctx context.Context, repo string, opts *ListOptions) ([]*PullRequest, error)
// GetPR retrieves a single pull request by number.
GetPR(ctx context.Context, repo string, number int) (*PullRequest, error)
// GetPRFiles returns the files changed in a pull request.
GetPRFiles(ctx context.Context, repo string, number int) ([]*ChangedFile, error)
// GetPRDiff returns the unified diff for a pull request.
GetPRDiff(ctx context.Context, repo string, number int) (string, error)
// ListPRCommits returns commits in a pull request.
ListPRCommits(ctx context.Context, repo string, number int) ([]*Commit, error)
// ListPRReviews returns reviews for a pull request, including
// inline comments nested under each review.
ListPRReviews(ctx context.Context, repo string, number int) ([]*Review, error)
// SubmitReview creates a new review on a pull request.
SubmitReview(ctx context.Context, repo string, number int, review *ReviewSubmission) (*Review, error)
// AddReviewComment posts an inline comment on a pull request diff.
AddReviewComment(ctx context.Context, repo string, number int, comment *ReviewComment) (*ReviewComment, error)
// ListChecks returns CI check runs for a pull request.
ListChecks(ctx context.Context, repo string, number int) ([]*CheckRun, error)
// MergePR merges a pull request using the specified method.
MergePR(ctx context.Context, repo string, number int, opts *MergeOptions) (*MergeResult, error)
// AddReaction adds an emoji reaction to an issue/PR or a specific
// comment. When commentID is 0, the reaction targets the
// issue/PR itself.
AddReaction(ctx context.Context, repo string, number int, commentID int64, emoji string) error
// RequestReview requests reviews from the specified users.
RequestReview(ctx context.Context, repo string, number int, reviewers []string) error
// Search performs a forge-native search of the given kind.
Search(ctx context.Context, query string, kind SearchKind, limit int) ([]SearchResult, error)
}
ForgeProvider is the interface that forge backends implement. All repository parameters use the "owner/repo" format — bare repo name resolution happens in the tool layer, not the provider.
type GitHub ¶
type GitHub struct {
// contains filtered or unexported fields
}
GitHub implements ForgeProvider for GitHub.com and GitHub Enterprise using the google/go-github SDK.
func NewGitHub ¶
func NewGitHub(httpClient *http.Client, token, baseURL string, logger *slog.Logger) (*GitHub, error)
NewGitHub creates a GitHub forge provider. The httpClient should be constructed via httpkit.NewClient. If baseURL is non-empty and not the default GitHub API URL, Enterprise URLs are configured.
func (*GitHub) AddComment ¶
func (g *GitHub) AddComment(ctx context.Context, repo string, number int, body string) (*Comment, error)
AddComment posts a comment on an issue or pull request.
func (*GitHub) AddReaction ¶
func (g *GitHub) AddReaction(ctx context.Context, repo string, number int, commentID int64, emoji string) error
AddReaction adds an emoji reaction to an issue/PR or a specific comment.
func (*GitHub) AddReviewComment ¶
func (g *GitHub) AddReviewComment(ctx context.Context, repo string, number int, comment *ReviewComment) (*ReviewComment, error)
AddReviewComment posts an inline comment on a pull request diff.
func (*GitHub) CreateIssue ¶
CreateIssue creates a new issue on the repository.
func (*GitHub) GetPRFiles ¶
GetPRFiles returns the files changed in a pull request.
func (*GitHub) ListChecks ¶
ListChecks returns CI check runs for a pull request.
func (*GitHub) ListIssues ¶
ListIssues returns issues matching the given filters.
func (*GitHub) ListPRCommits ¶
ListPRCommits returns commits in a pull request.
func (*GitHub) ListPRReviews ¶
ListPRReviews returns reviews for a pull request, including inline comments nested under each review.
func (*GitHub) ListPRs ¶
func (g *GitHub) ListPRs(ctx context.Context, repo string, opts *ListOptions) ([]*PullRequest, error)
ListPRs returns pull requests matching the given filters.
func (*GitHub) MergePR ¶
func (g *GitHub) MergePR(ctx context.Context, repo string, number int, opts *MergeOptions) (*MergeResult, error)
MergePR merges a pull request using the specified method.
func (*GitHub) RequestReview ¶
func (g *GitHub) RequestReview(ctx context.Context, repo string, number int, reviewers []string) error
RequestReview requests reviews from the specified users.
func (*GitHub) Search ¶
func (g *GitHub) Search(ctx context.Context, query string, kind SearchKind, limit int) ([]SearchResult, error)
Search performs a forge-native search of the given kind.
func (*GitHub) SubmitReview ¶
func (g *GitHub) SubmitReview(ctx context.Context, repo string, number int, review *ReviewSubmission) (*Review, error)
SubmitReview creates a new review on a pull request.
func (*GitHub) UpdateIssue ¶
func (g *GitHub) UpdateIssue(ctx context.Context, repo string, number int, update *IssueUpdate) (*Issue, error)
UpdateIssue applies a partial update to an existing issue.
type Issue ¶
type Issue struct {
// Number is the issue number (e.g., #42).
Number int
// Title is the issue title.
Title string
// Body is the full issue body in markdown.
Body string
// State is the issue lifecycle state: "open" or "closed".
State string
// Labels lists the label names applied to this issue.
Labels []string
// Assignees lists the usernames assigned to this issue.
Assignees []string
// Author is the username who created the issue.
Author string
// URL is the web URL for the issue.
URL string
// CreatedAt is when the issue was created.
CreatedAt time.Time
// UpdatedAt is when the issue was last modified.
UpdatedAt time.Time
// CommentCount is the number of comments on the issue.
CommentCount int
}
Issue represents a forge issue or pull request issue entry.
type IssueUpdate ¶
type IssueUpdate struct {
// Title replaces the issue title when non-nil.
Title *string
// Body REPLACES the entire issue body when non-nil — it does not
// append. Leave nil to keep the existing body unchanged.
Body *string
// State changes the issue state when non-nil: "open" or "closed".
State *string
// Labels REPLACES all labels when non-nil. Pass an empty slice to
// remove all labels.
Labels *[]string
// Assignees REPLACES all assignees when non-nil.
Assignees *[]string
}
IssueUpdate holds fields for updating an issue. Pointer fields distinguish "not provided" (nil) from "set to empty value".
type ListOptions ¶
type ListOptions struct {
// State filters by lifecycle state: "open", "closed", or "all".
State string
// Labels is a comma-separated label filter for issues.
Labels string
// Assignee filters issues by assignee username.
Assignee string
// Base filters PRs by target branch.
Base string
// Head filters PRs by source branch.
Head string
// Sort controls result ordering: "created", "updated", or
// "comments".
Sort string
// Direction controls sort direction: "asc" or "desc".
Direction string
// Limit caps the number of results per page (default 30, max 100).
Limit int
// Page selects the result page (1-indexed, default 1).
Page int
}
ListOptions controls pagination and filtering for list operations.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds configured forge providers and routes operations to the appropriate account. The first account is the primary (default).
func NewManager ¶
NewManager creates a forge manager from the given configuration. Each account is instantiated with its provider-specific implementation.
func (*Manager) Account ¶
func (m *Manager) Account(name string) (ForgeProvider, error)
Account returns the forge provider for the named account. If name is empty, the primary (first configured) account is used.
func (*Manager) AccountConfig ¶
func (m *Manager) AccountConfig(name string) (AccountConfig, error)
AccountConfig returns the configuration for the named account.
func (*Manager) Context ¶ added in v0.8.0
Context returns a markdown block describing the configured forge accounts for injection into a system prompt. The output is structured JSON wrapped in a fenced code block so the model can immediately identify available accounts, their types, and default owners without guessing. Returns an empty string when no accounts are configured. Tokens are never included.
type MergeOptions ¶
type MergeOptions struct {
// Method is the merge strategy: "squash" (default), "merge", or
// "rebase".
Method string
// CommitTitle overrides the merge commit title.
CommitTitle string
// CommitMessage overrides the merge commit body. Supports
// temp:LABEL references.
CommitMessage string
}
MergeOptions controls how a pull request is merged.
type MergeResult ¶
type MergeResult struct {
// SHA is the merge commit hash.
SHA string
// Message is the merge result message from the forge.
Message string
}
MergeResult reports the outcome of a pull request merge.
type Operation ¶ added in v0.9.1
type Operation struct {
Tool string `json:"tool"`
Account string `json:"account"`
Repo string `json:"repo"`
Ref string `json:"ref,omitempty"` // issue/PR number, search query, etc.
Timestamp time.Time `json:"-"` // formatted as delta at output time
}
Operation records a single forge tool invocation.
type OperationLog ¶ added in v0.9.1
type OperationLog struct {
// contains filtered or unexported fields
}
OperationLog tracks recent forge tool invocations in a bounded circular buffer. It is safe for concurrent use. Operations are recorded after successful tool execution and included in the forge capability context so delegates and subsequent turns know what's been happening.
func NewOperationLog ¶ added in v0.9.1
func NewOperationLog() *OperationLog
NewOperationLog creates an operation log with the default capacity.
func (*OperationLog) Len ¶ added in v0.9.1
func (l *OperationLog) Len() int
Len returns the number of operations currently stored.
func (*OperationLog) Recent ¶ added in v0.9.1
func (l *OperationLog) Recent(n int) []Operation
Recent returns the last n operations in reverse chronological order (newest first). Returns fewer than n if the log has fewer entries.
func (*OperationLog) Record ¶ added in v0.9.1
func (l *OperationLog) Record(op Operation)
Record adds a successful operation to the log. The timestamp is set automatically. Failed operations should not be recorded.
type PullRequest ¶
type PullRequest struct {
// Number is the PR number (e.g., #99).
Number int
// Title is the PR title.
Title string
// Body is the full PR description in markdown.
Body string
// State is the PR lifecycle state: "open", "closed", or "merged".
State string
// Draft indicates the PR is not ready for review.
Draft bool
// Author is the username who opened the PR.
Author string
// Head is the source branch name.
Head string
// Base is the target branch name.
Base string
// Mergeable indicates whether the PR can be merged cleanly. Nil
// means the mergeability check has not completed yet.
Mergeable *bool
// Labels lists the label names applied to this PR.
Labels []string
// Assignees lists the usernames assigned to this PR.
Assignees []string
// RequestedReviewers lists usernames whose review is requested.
RequestedReviewers []string
// ReviewState is the aggregate review status (e.g., "approved").
ReviewState string
// CommentCount is the number of comments on the PR.
CommentCount int
// Additions is the total lines added across all files.
Additions int
// Deletions is the total lines removed across all files.
Deletions int
// ChangedFiles is the number of files modified.
ChangedFiles int
// URL is the web URL for the PR.
URL string
// CreatedAt is when the PR was opened.
CreatedAt time.Time
// UpdatedAt is when the PR was last modified.
UpdatedAt time.Time
}
PullRequest represents a forge pull request.
type Review ¶
type Review struct {
// ID is the forge-assigned review identifier.
ID int64
// Author is the username who submitted the review.
Author string
// State is the review verdict: "APPROVED", "CHANGES_REQUESTED",
// "COMMENTED", or "DISMISSED".
State string
// Body is the review summary text.
Body string
// SubmittedAt is when the review was submitted.
SubmittedAt time.Time
// InlineComments are line-level comments attached to this review.
InlineComments []*ReviewComment
}
Review represents a pull request review with optional inline comments.
type ReviewComment ¶
type ReviewComment struct {
// ID is the forge-assigned comment identifier (zero for new comments).
ID int64
// Body is the comment text.
Body string
// Path is the file path in the diff.
Path string
// Line is the line number in the diff.
Line int
// Side selects the diff side: "LEFT" or "RIGHT" (default "RIGHT").
Side string
}
ReviewComment represents an inline comment on a pull request diff.
type ReviewSubmission ¶
type ReviewSubmission struct {
// Event is the review action: "APPROVE", "COMMENT", or
// "REQUEST_CHANGES".
Event string
// Body is the review summary text.
Body string
}
ReviewSubmission holds the parameters for submitting a new review.
type SearchKind ¶
type SearchKind string
SearchKind identifies the type of forge search to perform.
const ( // SearchIssues searches issues and pull requests. SearchIssues SearchKind = "issues" // SearchCode searches file contents. SearchCode SearchKind = "code" // SearchCommits searches commit messages and metadata. SearchCommits SearchKind = "commits" )
type SearchResult ¶
type SearchResult struct {
// Number is the issue or PR number (zero for non-issue results).
Number int
// Title is the result title or abbreviated SHA for commits.
Title string
// URL is the web URL for the result.
URL string
// Body is a snippet for code results or description for issues.
Body string
}
SearchResult represents a single search result from a forge.
type Tools ¶
type Tools struct {
// contains filtered or unexported fields
}
Tools holds forge tool dependencies. Each Handle* method takes the raw argument map from the tool registry and returns formatted text for the LLM. Prefix resolution (temp:LABEL, kb:file.md, etc.) is handled universally by the tool registry's ContentResolver before handlers run — individual handlers receive already-resolved content.
func NewTools ¶
func NewTools(mgr *Manager, opLog *OperationLog, logger *slog.Logger) *Tools
NewTools creates forge tools backed by the given manager. The opLog records successful operations for context injection; pass nil to disable operation tracking.
func (*Tools) HandleIssueComment ¶
HandleIssueComment posts a comment on an issue or pull request.
func (*Tools) HandleIssueCreate ¶
HandleIssueCreate creates a new issue on a forge repository.
func (*Tools) HandleIssueGet ¶
HandleIssueGet retrieves a single issue by number.
func (*Tools) HandleIssueList ¶
HandleIssueList lists issues matching the given filters.
func (*Tools) HandleIssueUpdate ¶
HandleIssueUpdate updates an existing issue. Body REPLACES the entire issue body when provided — it does not append.
func (*Tools) HandlePRChecks ¶
HandlePRChecks returns CI check runs for a pull request.
func (*Tools) HandlePRCommits ¶
HandlePRCommits returns commits in a pull request.
func (*Tools) HandlePRDiff ¶
HandlePRDiff returns the unified diff for a pull request, truncated at max_lines (default 2000).
func (*Tools) HandlePRFiles ¶
HandlePRFiles returns the files changed in a pull request.
func (*Tools) HandlePRGet ¶
HandlePRGet retrieves a single pull request by number.
func (*Tools) HandlePRList ¶
HandlePRList lists pull requests matching the given filters.
func (*Tools) HandlePRMerge ¶
HandlePRMerge merges a pull request.
func (*Tools) HandlePRReview ¶
HandlePRReview submits a review on a pull request.
func (*Tools) HandlePRReviewComment ¶
HandlePRReviewComment posts an inline comment on a pull request diff.
func (*Tools) HandlePRReviews ¶
HandlePRReviews returns reviews for a pull request with inline comments.
func (*Tools) HandleReact ¶
HandleReact adds an emoji reaction to an issue, PR, or comment.
func (*Tools) HandleRequestReview ¶
HandleRequestReview requests reviews from specified users.