pr

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package pr hosts reusable helpers for the pull request workflows that power the `magi pr` command. It includes prompt builders, AGENTS guideline loaders, and the AgenticReviewer used in cmd/pr.go so commands can share hardened logic without reimplementing multi-agent orchestration or sanitization steps.

Index

Constants

This section is empty.

Variables

View Source
var (
	AnalysisSchema = &openai.ChatCompletionNewParamsResponseFormatUnion{
		OfJSONSchema: &openaiShared.ResponseFormatJSONSchemaParam{
			JSONSchema: openaiShared.ResponseFormatJSONSchemaJSONSchemaParam{
				Name:        "analysis_result",
				Description: openai.String("The analysis result of the PR"),
				Schema: interface{}(map[string]interface{}{
					"type": "object",
					"properties": map[string]interface{}{
						"summary":                 map[string]interface{}{"type": "string"},
						"code_smells":             map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
						"security_concerns":       map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
						"agents_guideline_alerts": map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
						"test_recommendations":    map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
						"documentation_updates":   map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
						"risk_callouts":           map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
					},
					"required": []string{
						"summary",
						"code_smells",
						"security_concerns",
						"agents_guideline_alerts",
						"test_recommendations",
						"documentation_updates",
						"risk_callouts",
					},
					"additionalProperties": false,
				}),
				Strict: openai.Bool(true),
			},
		},
	}

	WriterSchema = &openai.ChatCompletionNewParamsResponseFormatUnion{
		OfJSONSchema: &openaiShared.ResponseFormatJSONSchemaParam{
			JSONSchema: openaiShared.ResponseFormatJSONSchemaJSONSchemaParam{
				Name:        "pr_content",
				Description: openai.String("The PR title and body"),
				Schema: interface{}(map[string]interface{}{
					"type": "object",
					"properties": map[string]interface{}{
						"title": map[string]interface{}{"type": "string"},
						"body":  map[string]interface{}{"type": "string"},
					},
					"required":             []string{"title", "body"},
					"additionalProperties": false,
				}),
				Strict: openai.Bool(true),
			},
		},
	}
)

Functions

func CollectAgentGuidelines

func CollectAgentGuidelines(root string) (string, error)

CollectAgentGuidelines aggregates every AGENTS.md file discovered under root.

func FormatFindingsComment

func FormatFindingsComment(findings AgentFindings) string

FormatFindingsComment produces a markdown comment from analysis findings.

func LoadPullRequestTemplate

func LoadPullRequestTemplate(path string) (string, error)

LoadPullRequestTemplate returns the contents of the GitHub pull request template.

func PRCmd

func PRCmd() *cobra.Command

Types

type AgentFindings

type AgentFindings struct {
	Summary               string   `json:"summary"`
	CodeSmells            []string `json:"code_smells"`
	SecurityConcerns      []string `json:"security_concerns"`
	AgentsGuidelineAlerts []string `json:"agents_guideline_alerts"`
	TestRecommendations   []string `json:"test_recommendations"`
	DocumentationUpdates  []string `json:"documentation_updates"`
	RiskCallouts          []string `json:"risk_callouts"`
}

AgentFindings captures the structured response from the analysis agent.

type AgenticReviewer

type AgenticReviewer struct {
	// contains filtered or unexported fields
}

AgenticReviewer orchestrates the agent workflow for PR prep.

func NewAgenticReviewer

func NewAgenticReviewer(runtime *shared.RuntimeContext) *AgenticReviewer

NewAgenticReviewer creates a reviewer bound to the shared runtime context.

func (*AgenticReviewer) Review

func (r *AgenticReviewer) Review(ctx context.Context, input ReviewInput) (*ReviewArtifacts, error)

Review executes the multi-agent workflow and returns structured artifacts.

type AnalysisAgent

type AnalysisAgent struct {
	// contains filtered or unexported fields
}

AnalysisAgent performs the initial code analysis

func NewAnalysisAgent

func NewAnalysisAgent(runtime *shared.RuntimeContext) *AnalysisAgent

func (*AnalysisAgent) Execute

func (a *AnalysisAgent) Execute(input map[string]string) (string, error)

func (*AnalysisAgent) Name

func (a *AnalysisAgent) Name() string

func (*AnalysisAgent) WaitForResults

func (a *AnalysisAgent) WaitForResults() []string

type PullRequestPlan

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

PullRequestPlan stores the generated title and filled template.

type ReviewArtifacts

type ReviewArtifacts struct {
	Analysis AgentFindings
	Plan     PullRequestPlan
}

ReviewArtifacts groups the analysis findings with the final PR plan.

type ReviewInput

type ReviewInput struct {
	Diff              string
	Branch            string
	RemoteRef         string
	Guidelines        string
	AdditionalContext string
	Template          string
}

ReviewInput encapsulates the information sent to the analysis workflow.

type WriterAgent

type WriterAgent struct {
	// contains filtered or unexported fields
}

WriterAgent generates the PR description

func NewWriterAgent

func NewWriterAgent(runtime *shared.RuntimeContext) *WriterAgent

func (*WriterAgent) Execute

func (a *WriterAgent) Execute(input map[string]string) (string, error)

func (*WriterAgent) Name

func (a *WriterAgent) Name() string

func (*WriterAgent) WaitForResults

func (a *WriterAgent) WaitForResults() []string

Jump to

Keyboard shortcuts

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