models

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: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandCode     = "/code"
	CommandContinue = "/continue"
	CommandFix      = "/fix"
)

命令类型

View Source
const (
	AIModelClaude = "claude"
	AIModelGemini = "gemini"
)

AI模型类型

View Source
const (
	// 章节标题
	SectionSummary  = "## 改动摘要"
	SectionChanges  = "## 具体改动"
	SectionTestPlan = "## 测试计划"

	// 章节标识符(用于解析)
	SectionSummaryID  = "summary"
	SectionChangesID  = "changes"
	SectionTestPlanID = "testPlan"

	// 错误标识符
	ErrorPrefixError     = "error:"
	ErrorPrefixException = "exception:"
	ErrorPrefixTraceback = "traceback:"
	ErrorPrefixPanic     = "panic:"
)

三段式输出相关的常量

View Source
const (
	TaskNameGatherContext     = "gather-context"     // 收集上下文
	TaskNameSetupWorkspace    = "setup-workspace"    // 设置工作空间
	TaskNameGenerateCode      = "generate-code"      // 生成代码
	TaskNameCommitChanges     = "commit-changes"     // 提交更改
	TaskNameCreatePR          = "create-pr"          // 创建PR
	TaskNameUpdatePR          = "update-pr"          // 更新PR
	TaskNameAnalyzeChanges    = "analyze-changes"    // 分析更改
	TaskNamePrepareWorkspace  = "prepare-workspace"  // 准备工作空间
	TaskNameImplementChanges  = "implement-changes"  // 实现更改
	TaskNameCommitUpdates     = "commit-updates"     // 提交更新
	TaskNameIdentifyProblems  = "identify-problems"  // 识别问题
	TaskNameApplyFixes        = "apply-fixes"        // 应用修复
	TaskNameCommitFixes       = "commit-fixes"       // 提交修复
	TaskNameAnalyzeCode       = "analyze-code"       // 分析代码
	TaskNameRunChecks         = "run-checks"         // 运行检查
	TaskNameGenerateReview    = "generate-review"    // 生成审查
	TaskNameSubmitReview      = "submit-review"      // 提交审查
	TaskNameProcessComments   = "process-comments"   // 处理评论
	TaskNameImplementFeedback = "implement-feedback" // 实现反馈
)

TaskName 任务名称常量

Variables

View Source
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

SpinnerFrames Spinner动画帧

Functions

func IsValidEventType

func IsValidEventType(eventType string) bool

IsValidEventType 检查事件类型是否有效

Types

type BaseContext

type BaseContext struct {
	Type       EventType          `json:"type"`
	Repository *github.Repository `json:"repository"`
	Sender     *github.User       `json:"sender"`
	RawEvent   interface{}        `json:"raw_event"`
	Action     string             `json:"action"`
	DeliveryID string             `json:"delivery_id"`
	Timestamp  time.Time          `json:"timestamp"`
}

BaseContext provides base implementation for all event contexts

func (*BaseContext) GetDeliveryID

func (bc *BaseContext) GetDeliveryID() string

func (*BaseContext) GetEventAction

func (bc *BaseContext) GetEventAction() string

func (*BaseContext) GetEventType

func (bc *BaseContext) GetEventType() EventType

func (*BaseContext) GetRawEvent

func (bc *BaseContext) GetRawEvent() interface{}

func (*BaseContext) GetRepository

func (bc *BaseContext) GetRepository() *github.Repository

func (*BaseContext) GetSender

func (bc *BaseContext) GetSender() *github.User

func (*BaseContext) GetTimestamp

func (bc *BaseContext) GetTimestamp() time.Time

type CommandInfo

type CommandInfo struct {
	Command string `json:"command"`  // /code, /continue, /fix
	AIModel string `json:"ai_model"` // claude, gemini
	Args    string `json:"args"`     // 命令参数
	RawText string `json:"raw_text"` // 原始文本
}

CommandInfo 提取的命令信息

func HasCommand

func HasCommand(ctx GitHubContext) (*CommandInfo, bool)

HasCommand 检查上下文是否包含命令

type CommentContext

type CommentContext struct {
	Repository     *github.Repository `json:"repository"`
	IssueNumber    int                `json:"issue_number"`
	CommentID      *int64             `json:"comment_id,omitempty"`
	InitialContent string             `json:"initial_content"`
	LastContent    string             `json:"last_content"`
	UpdateCount    int                `json:"update_count"`
	CreatedAt      time.Time          `json:"created_at"`
	LastUpdatedAt  *time.Time         `json:"last_updated_at,omitempty"`
}

CommentContext 评论上下文

type EventType

type EventType string

EventType defines GitHub event types

const (
	EventIssueComment             EventType = "issue_comment"
	EventPullRequestReview        EventType = "pull_request_review"
	EventPullRequestReviewComment EventType = "pull_request_review_comment"
	EventIssues                   EventType = "issues"
	EventPullRequest              EventType = "pull_request"
	EventWorkflowDispatch         EventType = "workflow_dispatch"
	EventSchedule                 EventType = "schedule"
	EventPush                     EventType = "push"
)

type ExecutionMetrics

type ExecutionMetrics struct {
	ToolCalls     int           `json:"tool_calls"`
	Duration      time.Duration `json:"duration"`
	Success       int           `json:"success"`
	Errors        int           `json:"errors"`
	LastExecution time.Time     `json:"last_execution"`
}

ExecutionMetrics 执行指标

type ExecutionResult

type ExecutionResult struct {
	Success      bool          `json:"success"`
	Output       string        `json:"output"`
	Error        string        `json:"error,omitempty"`
	FilesChanged []string      `json:"files_changed"`
	Duration     time.Duration `json:"duration"`
}

type GitHubContext

type GitHubContext interface {
	GetEventType() EventType
	GetRepository() *github.Repository
	GetSender() *github.User
	GetRawEvent() interface{}
	GetEventAction() string
	GetDeliveryID() string
	GetTimestamp() time.Time
}

GitHubContext is the interface for all GitHub event contexts

type IssueCommentContext

type IssueCommentContext struct {
	BaseContext
	Issue   *github.Issue        `json:"issue"`
	Comment *github.IssueComment `json:"comment"`
	// 是否是PR评论(通过Issue.PullRequestLinks判断)
	IsPRComment bool `json:"is_pr_comment"`
}

IssueCommentContext Issue评论事件上下文

type IssuesContext

type IssuesContext struct {
	BaseContext
	Issue *github.Issue `json:"issue"`
}

IssuesContext Issue事件上下文

type JSONSchema

type JSONSchema struct {
	Type                 string                 `json:"type"`
	Properties           map[string]*JSONSchema `json:"properties,omitempty"`
	Required             []string               `json:"required,omitempty"`
	Items                *JSONSchema            `json:"items,omitempty"`
	Description          string                 `json:"description,omitempty"`
	Enum                 []interface{}          `json:"enum,omitempty"`
	AdditionalProperties bool                   `json:"additionalProperties,omitempty"`
}

JSONSchema JSON Schema定义

type MCPContext

type MCPContext struct {
	// 基础上下文
	Repository  GitHubContext `json:"repository"`
	Issue       interface{}   `json:"issue,omitempty"`
	PullRequest interface{}   `json:"pull_request,omitempty"`
	User        interface{}   `json:"user,omitempty"`

	// 工作环境
	WorkspacePath string            `json:"workspace_path,omitempty"`
	BranchName    string            `json:"branch_name,omitempty"`
	Metadata      map[string]string `json:"metadata,omitempty"`

	// 权限控制
	Permissions []string `json:"permissions,omitempty"`
	Constraints []string `json:"constraints,omitempty"`
}

MCPContext MCP执行上下文

type MCPError

type MCPError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data,omitempty"`
}

MCPError MCP错误

type MCPRequest

type MCPRequest struct {
	ID     string                 `json:"id"`
	Method string                 `json:"method"`
	Params map[string]interface{} `json:"params"`
}

MCPRequest MCP协议请求

type MCPResponse

type MCPResponse struct {
	ID     string      `json:"id"`
	Result interface{} `json:"result,omitempty"`
	Error  *MCPError   `json:"error,omitempty"`
}

MCPResponse MCP协议响应

type MCPServerCapabilities

type MCPServerCapabilities struct {
	Tools     []Tool `json:"tools"`
	Resources []any  `json:"resources,omitempty"`
	Prompts   []any  `json:"prompts,omitempty"`
}

MCPServerCapabilities MCP服务器能力声明

type MCPServerInfo

type MCPServerInfo struct {
	Name         string                `json:"name"`
	Version      string                `json:"version"`
	Description  string                `json:"description"`
	Capabilities MCPServerCapabilities `json:"capabilities"`
	CreatedAt    time.Time             `json:"created_at"`
}

MCPServerInfo MCP服务器信息

type PRAllComments

type PRAllComments struct {
	PRBody         string                       `json:"pr_body"`
	IssueComments  []*github.IssueComment       `json:"issue_comments"`
	ReviewComments []*github.PullRequestComment `json:"review_comments"`
	Reviews        []*github.PullRequestReview  `json:"reviews"`
}

PRAllComments 包含 PR 的所有评论信息

type ProgressExecutionResult

type ProgressExecutionResult struct {
	Success        bool                   `json:"success"`
	Output         string                 `json:"output"`
	Error          string                 `json:"error,omitempty"`
	FilesChanged   []string               `json:"files_changed"`
	Duration       time.Duration          `json:"duration"`
	Summary        string                 `json:"summary"`
	CommitSHA      string                 `json:"commit_sha,omitempty"`
	BranchName     string                 `json:"branch_name,omitempty"`
	PullRequestURL string                 `json:"pull_request_url,omitempty"`
	TaskResults    []*Task                `json:"task_results"`
	Metadata       map[string]interface{} `json:"metadata,omitempty"`
}

ProgressExecutionResult 带进度信息的执行结果

type ProgressTracker

type ProgressTracker struct {
	Tasks           []*Task       `json:"tasks"`
	CurrentTaskName string        `json:"current_task_name"`
	StartTime       time.Time     `json:"start_time"`
	EndTime         *time.Time    `json:"end_time,omitempty"`
	Status          TaskStatus    `json:"status"`
	Spinner         *SpinnerState `json:"spinner"`
	TotalDuration   time.Duration `json:"total_duration"`
}

ProgressTracker 进度跟踪器

func NewProgressTracker

func NewProgressTracker() *ProgressTracker

NewProgressTracker 创建新的进度跟踪器

func (*ProgressTracker) AddTask

func (pt *ProgressTracker) AddTask(task *Task)

AddTask 添加任务

func (*ProgressTracker) Complete

func (pt *ProgressTracker) Complete()

Complete 完成整个进度跟踪

func (*ProgressTracker) CompleteCurrentTask

func (pt *ProgressTracker) CompleteCurrentTask()

CompleteCurrentTask 完成当前任务

func (*ProgressTracker) Fail

func (pt *ProgressTracker) Fail(err error)

Fail 整个进度跟踪失败

func (*ProgressTracker) FailCurrentTask

func (pt *ProgressTracker) FailCurrentTask(err error)

FailCurrentTask 当前任务失败

func (*ProgressTracker) GetCompletedTasksCount

func (pt *ProgressTracker) GetCompletedTasksCount() int

GetCompletedTasksCount 获取已完成任务数量

func (*ProgressTracker) GetCurrentTask

func (pt *ProgressTracker) GetCurrentTask() *Task

GetCurrentTask 获取当前任务

func (*ProgressTracker) GetFailedTasksCount

func (pt *ProgressTracker) GetFailedTasksCount() int

GetFailedTasksCount 获取失败任务数量

func (*ProgressTracker) GetOverallProgress

func (pt *ProgressTracker) GetOverallProgress() float64

GetOverallProgress 获取整体进度

func (*ProgressTracker) GetTask

func (pt *ProgressTracker) GetTask(name string) *Task

GetTask 根据Name获取任务

func (*ProgressTracker) HasErrors

func (pt *ProgressTracker) HasErrors() bool

HasErrors 检查是否有错误

func (*ProgressTracker) SetCurrentTask

func (pt *ProgressTracker) SetCurrentTask(name string)

SetCurrentTask 设置当前任务

func (*ProgressTracker) StartSpinner

func (pt *ProgressTracker) StartSpinner(message string)

StartSpinner 开始Spinner动画

func (*ProgressTracker) StopSpinner

func (pt *ProgressTracker) StopSpinner()

StopSpinner 停止Spinner动画

type PullRequestContext

type PullRequestContext struct {
	BaseContext
	PullRequest *github.PullRequest `json:"pull_request"`
}

PullRequestContext PR事件上下文

type PullRequestReviewCommentContext

type PullRequestReviewCommentContext struct {
	BaseContext
	PullRequest *github.PullRequest        `json:"pull_request"`
	Comment     *github.PullRequestComment `json:"comment"`
}

PullRequestReviewCommentContext PR Review评论事件上下文

type PullRequestReviewContext

type PullRequestReviewContext struct {
	BaseContext
	PullRequest *github.PullRequest       `json:"pull_request"`
	Review      *github.PullRequestReview `json:"review"`
}

PullRequestReviewContext PR Review事件上下文

type PushContext

type PushContext struct {
	BaseContext
	Ref     string               `json:"ref"`
	Commits []*github.HeadCommit `json:"commits"`
	Before  string               `json:"before"`
	After   string               `json:"after"`
}

PushContext push事件上下文

type ScheduleContext

type ScheduleContext struct {
	BaseContext
	Cron string `json:"cron"`
}

ScheduleContext schedule事件上下文

type SpinnerState

type SpinnerState struct {
	Active     bool      `json:"active"`
	Message    string    `json:"message"`
	StartTime  time.Time `json:"start_time"`
	FrameIndex int       `json:"frame_index"`
}

SpinnerState Spinner动画状态

func (*SpinnerState) GetCurrentFrame

func (s *SpinnerState) GetCurrentFrame() string

GetCurrentFrame 获取当前动画帧

func (*SpinnerState) Start

func (s *SpinnerState) Start(message string)

Start 开始Spinner动画

func (*SpinnerState) Stop

func (s *SpinnerState) Stop()

Stop 停止Spinner动画

type Task

type Task struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Status      TaskStatus        `json:"status"`
	StartTime   *time.Time        `json:"start_time,omitempty"`
	EndTime     *time.Time        `json:"end_time,omitempty"`
	Duration    time.Duration     `json:"duration"`
	Error       string            `json:"error,omitempty"`
	SubTasks    []*Task           `json:"sub_tasks,omitempty"`
	Progress    float64           `json:"progress"` // 0.0 - 1.0
	Metadata    map[string]string `json:"metadata,omitempty"`
}

Task 代表一个可跟踪的任务

func NewTask

func NewTask(name, description string) *Task

NewTask 创建新任务

func (*Task) Complete

func (t *Task) Complete()

Complete 完成任务

func (*Task) Fail

func (t *Task) Fail(err error)

Fail 任务失败

func (*Task) GetStatusIcon

func (t *Task) GetStatusIcon() string

GetStatusIcon 获取状态对应的图标

func (*Task) IsActive

func (t *Task) IsActive() bool

IsActive 检查任务是否处于活动状态

func (*Task) IsCompleted

func (t *Task) IsCompleted() bool

IsCompleted 检查任务是否已完成

func (*Task) IsFailed

func (t *Task) IsFailed() bool

IsFailed 检查任务是否失败

func (*Task) SetProgress

func (t *Task) SetProgress(progress float64)

SetProgress 设置任务进度

func (*Task) Skip

func (t *Task) Skip(reason string)

Skip 跳过任务

func (*Task) Start

func (t *Task) Start()

Start 开始执行任务

type TaskStatus

type TaskStatus string

TaskStatus 任务状态枚举

const (
	TaskStatusPending    TaskStatus = "pending"     // ⏳ 等待执行
	TaskStatusInProgress TaskStatus = "in_progress" // 🔄 正在执行
	TaskStatusCompleted  TaskStatus = "completed"   // ✅ 已完成
	TaskStatusFailed     TaskStatus = "failed"      // ❌ 执行失败
	TaskStatusSkipped    TaskStatus = "skipped"     // ⏭️ 已跳过
)

type Tool

type Tool struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	InputSchema *JSONSchema `json:"input_schema"`
}

Tool MCP工具定义

type ToolCall

type ToolCall struct {
	ID       string                 `json:"id"`
	Function ToolFunction           `json:"function"`
	Context  map[string]interface{} `json:"context,omitempty"`
}

ToolCall 工具调用

type ToolFunction

type ToolFunction struct {
	Name      string                 `json:"name"`
	Arguments map[string]interface{} `json:"arguments"`
}

ToolFunction 工具函数

type ToolResult

type ToolResult struct {
	ID      string      `json:"id"`
	Success bool        `json:"success"`
	Content interface{} `json:"content,omitempty"`
	Error   string      `json:"error,omitempty"`
	Type    string      `json:"type,omitempty"` // text, json, image, etc.
}

ToolResult 工具执行结果

type WorkflowDispatchContext

type WorkflowDispatchContext struct {
	BaseContext
	Inputs map[string]interface{} `json:"inputs"`
}

WorkflowDispatchContext workflow_dispatch事件上下文

type Workspace

type Workspace struct {
	// github org name
	Org string `json:"org"`
	// github repo name
	Repo string `json:"repo"`
	// PR number
	PRNumber int `json:"pr_number"`
	// AI model name (claude or gemini)
	AIModel string `json:"ai_model"`
	// workspace path in local file system
	Path string `json:"path"`
	// session path in local file system
	SessionPath string `json:"session_path"`
	// github repo url
	Repository string `json:"repository"`
	// github branch name
	Branch      string              `json:"branch"`
	Issue       *github.Issue       `json:"issue"`
	PullRequest *github.PullRequest `json:"pull_request"`
	CreatedAt   time.Time           `json:"created_at"`
}

Jump to

Keyboard shortcuts

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