pr

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 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"}},
						"needs_i18n":              map[string]interface{}{"type": "boolean"},
						"i18n_reason":             map[string]interface{}{"type": "string"},
					},
					"required": []string{
						"summary",
						"code_smells",
						"security_concerns",
						"agents_guideline_alerts",
						"test_recommendations",
						"documentation_updates",
						"risk_callouts",
						"needs_i18n",
						"i18n_reason",
					},
					"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),
			},
		},
	}

	I18nSchema = &openai.ChatCompletionNewParamsResponseFormatUnion{
		OfJSONSchema: &openaiShared.ResponseFormatJSONSchemaParam{
			JSONSchema: openaiShared.ResponseFormatJSONSchemaJSONSchemaParam{
				Name:        "i18n_result",
				Description: openai.String("Extracted translation keys and values"),
				Schema: interface{}(map[string]interface{}{
					"type": "object",
					"properties": map[string]interface{}{
						"translations": map[string]interface{}{
							"type": "array",
							"items": map[string]interface{}{
								"type": "object",
								"properties": map[string]interface{}{
									"key":      map[string]interface{}{"type": "string"},
									"value_en": map[string]interface{}{"type": "string"},
									"value_de": map[string]interface{}{"type": "string"},
								},
								"required":             []string{"key", "value_en", "value_de"},
								"additionalProperties": false,
							},
						},
					},
					"required":             []string{"translations"},
					"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(artifacts ReviewArtifacts) 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"`
	NeedsI18n             bool     `json:"needs_i18n"`
	I18nReason            string   `json:"i18n_reason"`
}

AgentFindings captures the structured response from the analysis agent. 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 I18nAgent added in v0.8.1

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

I18nAgent automatically generates translations for new user-facing strings

func NewI18nAgent added in v0.8.1

func NewI18nAgent(runtime *shared.RuntimeContext) *I18nAgent

func (*I18nAgent) Execute added in v0.8.1

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

func (*I18nAgent) Name added in v0.8.1

func (a *I18nAgent) Name() string

func (*I18nAgent) WaitForResults added in v0.8.1

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

type I18nResult added in v0.8.1

type I18nResult struct {
	Translations []TranslationItem `json:"translations"`
}

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
	I18nFindings *I18nResult
}

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 TranslationItem added in v0.8.1

type TranslationItem struct {
	Key     string `json:"key"`
	ValueEn string `json:"value_en"`
	ValueDe string `json:"value_de"`
}

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