context

package
v0.0.0-...-e487a75 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeContext

type CodeContext struct {
	Repository   string       `json:"repository"`
	BaseBranch   string       `json:"base_branch"`
	HeadBranch   string       `json:"head_branch,omitempty"`
	Files        []FileChange `json:"files"`
	TotalChanges struct {
		Additions int `json:"additions"`
		Deletions int `json:"deletions"`
		Files     int `json:"files"`
	} `json:"total_changes"`
}

CodeContext 代码上下文

type CommentContext

type CommentContext struct {
	ID        int64     `json:"id"`
	Type      string    `json:"type"` // comment, review_comment, review
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	// For review comments
	FilePath   string `json:"file_path,omitempty"`
	LineNumber int    `json:"line_number,omitempty"`
	StartLine  int    `json:"start_line,omitempty"`
	// For reviews
	ReviewState string `json:"review_state,omitempty"`
}

CommentContext 评论上下文

type ContextCollector

type ContextCollector interface {
	// 收集基础上下文
	CollectBasicContext(eventType string, payload interface{}) (*EnhancedContext, error)

	// 收集代码上下文
	CollectCodeContext(pr *github.PullRequest) (*CodeContext, error)

	// 收集GitHub上下文
	CollectGitHubContext(repoFullName string, prNumber int) (*GitHubContext, error)

	// 收集评论上下文
	CollectCommentContext(pr *github.PullRequest, currentCommentID int64) ([]CommentContext, error)
}

ContextCollector 上下文收集器接口

type ContextFormatter

type ContextFormatter interface {
	// 格式化为Markdown
	FormatToMarkdown(ctx *EnhancedContext) (string, error)

	// 格式化为结构化文本
	FormatToStructured(ctx *EnhancedContext) (string, error)

	// 智能裁剪
	TrimToTokenLimit(ctx *EnhancedContext, maxTokens int) (*EnhancedContext, error)
}

ContextFormatter 上下文格式化器接口

type ContextManager

type ContextManager struct {
	Collector ContextCollector
	Formatter ContextFormatter
	Generator PromptGenerator
}

ContextManager 上下文管理器

type ContextPriority

type ContextPriority int

ContextPriority 上下文优先级

const (
	PriorityLow      ContextPriority = 1
	PriorityMedium   ContextPriority = 2
	PriorityHigh     ContextPriority = 3
	PriorityCritical ContextPriority = 4
)

type ContextType

type ContextType string

ContextType 上下文类型

const (
	ContextTypePR            ContextType = "pull_request"
	ContextTypeIssue         ContextType = "issue"
	ContextTypePRComment     ContextType = "pr_comment"
	ContextTypeReviewComment ContextType = "review_comment"
	ContextTypeReview        ContextType = "review"
)

type DefaultContextCollector

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

DefaultContextCollector 默认上下文收集器实现

func NewDefaultContextCollector

func NewDefaultContextCollector(githubClient *ghclient.Client) *DefaultContextCollector

NewDefaultContextCollector 创建默认上下文收集器

func (*DefaultContextCollector) CollectBasicContext

func (c *DefaultContextCollector) CollectBasicContext(eventType string, payload interface{}) (*EnhancedContext, error)

CollectBasicContext 收集基础上下文

func (*DefaultContextCollector) CollectCodeContext

func (c *DefaultContextCollector) CollectCodeContext(pr *github.PullRequest) (*CodeContext, error)

CollectCodeContext 收集代码上下文

func (*DefaultContextCollector) CollectCommentContext

func (c *DefaultContextCollector) CollectCommentContext(pr *github.PullRequest, currentCommentID int64) ([]CommentContext, error)

CollectCommentContext 收集评论上下文

func (*DefaultContextCollector) CollectGitHubContext

func (c *DefaultContextCollector) CollectGitHubContext(repoFullName string, prNumber int) (*GitHubContext, error)

CollectGitHubContext 收集GitHub上下文信息 专注于GitHub原生数据收集

type DefaultContextFormatter

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

DefaultContextFormatter 默认上下文格式化器实现

func NewDefaultContextFormatter

func NewDefaultContextFormatter(maxTokens int) *DefaultContextFormatter

NewDefaultContextFormatter 创建默认上下文格式化器

func (*DefaultContextFormatter) FormatToMarkdown

func (f *DefaultContextFormatter) FormatToMarkdown(ctx *EnhancedContext) (string, error)

FormatToMarkdown 格式化为Markdown

func (*DefaultContextFormatter) FormatToStructured

func (f *DefaultContextFormatter) FormatToStructured(ctx *EnhancedContext) (string, error)

FormatToStructured 格式化为结构化文本

func (*DefaultContextFormatter) TrimToTokenLimit

func (f *DefaultContextFormatter) TrimToTokenLimit(ctx *EnhancedContext, maxTokens int) (*EnhancedContext, error)

TrimToTokenLimit 智能裁剪到token限制

type DefaultPromptGenerator

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

DefaultPromptGenerator 默认提示词生成器实现

func NewDefaultPromptGenerator

func NewDefaultPromptGenerator(formatter ContextFormatter) *DefaultPromptGenerator

NewDefaultPromptGenerator 创建默认提示词生成器

func (*DefaultPromptGenerator) GeneratePrompt

func (g *DefaultPromptGenerator) GeneratePrompt(ctx *EnhancedContext, mode string, args string) (string, error)

GeneratePrompt 生成基础提示词

func (*DefaultPromptGenerator) GenerateSystemPrompt

func (g *DefaultPromptGenerator) GenerateSystemPrompt(ctx *EnhancedContext) (string, error)

GenerateSystemPrompt 生成系统提示词

func (*DefaultPromptGenerator) GenerateToolsList

func (g *DefaultPromptGenerator) GenerateToolsList(ctx *EnhancedContext, mode string) ([]string, error)

GenerateToolsList 生成工具列表

type EnhancedContext

type EnhancedContext struct {
	// 基础信息
	Type      ContextType     `json:"type"`
	Priority  ContextPriority `json:"priority"`
	Timestamp time.Time       `json:"timestamp"`

	// 核心数据
	Subject  interface{}      `json:"subject"` // PR, Issue, or Comment
	Comments []CommentContext `json:"comments"`
	Code     *CodeContext     `json:"code,omitempty"`

	// 元数据
	Metadata   map[string]interface{} `json:"metadata"`
	TokenCount int                    `json:"token_count,omitempty"`
}

EnhancedContext 增强上下文

type Factory

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

Factory 上下文工厂,提供统一的创建和管理接口

func NewFactory

func NewFactory(githubClient *ghclient.Client, logger *xlog.Logger) *Factory

NewFactory 创建新的上下文工厂

func (*Factory) CreateEnhancedContext

func (f *Factory) CreateEnhancedContext(eventType string, payload interface{}) (*EnhancedContext, error)

CreateEnhancedContext 创建增强上下文(简化版本,专注于GitHub数据)

func (*Factory) CreateGitHubContext

func (f *Factory) CreateGitHubContext(repoFullName string, prNumber int) (*GitHubContext, error)

CreateGitHubContext 创建GitHub原生上下文

func (*Factory) CreateManager

func (f *Factory) CreateManager() *ContextManager

CreateManager 创建上下文管理器

func (*Factory) FormatToMarkdown

func (f *Factory) FormatToMarkdown(ctx *EnhancedContext) (string, error)

FormatToMarkdown 格式化为Markdown

func (*Factory) FormatToStructured

func (f *Factory) FormatToStructured(ctx *EnhancedContext) (string, error)

FormatToStructured 格式化为结构化文本

func (*Factory) GeneratePromptWithContext

func (f *Factory) GeneratePromptWithContext(ctx *EnhancedContext, mode string, args string) (string, error)

GeneratePromptWithContext 使用上下文生成提示词

func (*Factory) GetCollector

func (f *Factory) GetCollector() ContextCollector

GetCollector 获取上下文收集器

func (*Factory) GetFormatter

func (f *Factory) GetFormatter() ContextFormatter

GetFormatter 获取上下文格式化器

func (*Factory) GetGenerator

func (f *Factory) GetGenerator() PromptGenerator

GetGenerator 获取提示词生成器

func (*Factory) TrimContext

func (f *Factory) TrimContext(ctx *EnhancedContext, maxTokens int) (*EnhancedContext, error)

TrimContext 智能裁剪上下文到指定token限制

type FileChange

type FileChange struct {
	Path         string `json:"path"`
	Status       string `json:"status"` // added, modified, deleted, renamed
	Additions    int    `json:"additions"`
	Deletions    int    `json:"deletions"`
	Changes      int    `json:"changes"`
	Patch        string `json:"patch,omitempty"`
	PreviousPath string `json:"previous_path,omitempty"` // for renamed files
	SHA          string `json:"sha,omitempty"`
}

FileChange 文件变更信息

type GitHubContext

type GitHubContext struct {
	Repository  string              `json:"repository"`
	PRNumber    int                 `json:"pr_number,omitempty"`
	IssueNumber int                 `json:"issue_number,omitempty"`
	PR          *PullRequestContext `json:"pr,omitempty"`
	Issue       *IssueContext       `json:"issue,omitempty"`
	Files       []FileChange        `json:"files"`
	Comments    []CommentContext    `json:"comments"`
}

GitHubContext GitHub原生上下文

type IssueContext

type IssueContext struct {
	Number int    `json:"number"`
	Title  string `json:"title"`
	Body   string `json:"body"`
	State  string `json:"state"`
	Author string `json:"author"`
}

type PRFormatter

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

PRFormatter 专门用于格式化PR描述 提供优雅、结构化的PR描述格式

func NewPRFormatter

func NewPRFormatter() *PRFormatter

NewPRFormatter 创建新的PR格式化器

func (*PRFormatter) FormatPRDescription

func (f *PRFormatter) FormatPRDescription(
	issueTitle string,
	issueBody string,
	summary string,
	changes string,
	testPlan string,
	aiOutput string,
	issueNumber int,
) string

FormatPRDescription 格式化PR描述 提供简洁、核心的PR描述

func (*PRFormatter) GenerateSimpleSummary

func (f *PRFormatter) GenerateSimpleSummary(issueTitle string, issueNumber int) string

GenerateSimpleSummary 生成简单的摘要

type PromptGenerator

type PromptGenerator interface {
	// 生成基础提示词
	GeneratePrompt(ctx *EnhancedContext, mode string, args string) (string, error)

	// 生成工具列表
	GenerateToolsList(ctx *EnhancedContext, mode string) ([]string, error)

	// 生成系统提示词
	GenerateSystemPrompt(ctx *EnhancedContext) (string, error)
}

PromptGenerator 提示词生成器接口

type PullRequestContext

type PullRequestContext struct {
	Number     int    `json:"number"`
	Title      string `json:"title"`
	Body       string `json:"body"`
	State      string `json:"state"`
	Author     string `json:"author"`
	BaseBranch string `json:"base_branch"`
	HeadBranch string `json:"head_branch"`
	Additions  int    `json:"additions"`
	Deletions  int    `json:"deletions"`
	Commits    int    `json:"commits"`
}

type TemplatePromptGenerator

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

TemplatePromptGenerator template-based prompt generator

func NewTemplatePromptGenerator

func NewTemplatePromptGenerator(formatter ContextFormatter) *TemplatePromptGenerator

NewTemplatePromptGenerator creates a new template generator

func (*TemplatePromptGenerator) GeneratePrompt

func (g *TemplatePromptGenerator) GeneratePrompt(ctx *EnhancedContext, mode string, args string) (string, error)

GeneratePrompt generates prompts using templates

func (*TemplatePromptGenerator) GenerateSystemPrompt

func (g *TemplatePromptGenerator) GenerateSystemPrompt(ctx *EnhancedContext) (string, error)

GenerateSystemPrompt 生成系统提示词

func (*TemplatePromptGenerator) GenerateToolsList

func (g *TemplatePromptGenerator) GenerateToolsList(ctx *EnhancedContext, mode string) ([]string, error)

GenerateToolsList 生成工具列表

Jump to

Keyboard shortcuts

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