agent

package
v1.0.50 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PromptCommitMessage = `` /* 579-byte string literal not displayed */

	PromptWorkflowContext = `` /* 1018-byte string literal not displayed */

	PromptNotesUpdateExisting = `` /* 141-byte string literal not displayed */

	PromptNotesCreateNew = `Create a %s file with relevant context and instructions for the next iteration.`

	PromptNotesGuidelines = `` /* 445-byte string literal not displayed */

	PromptReviewerContext = `` /* 324-byte string literal not displayed */

	PromptCIFixContext = `` /* 825-byte string literal not displayed */

)
View Source
const (
	CompletionSignal      = "CONTINUOUS_PROJECT_COMPLETE"
	MaxConsecutiveErrors  = 3
	IterationDelaySeconds = 1
)

Variables

This section is empty.

Functions

func AttemptCIFixAndRecheck

func AttemptCIFixAndRecheck(ctx *Context, prNumber, branchName string, display func() string) bool

func BuildEnhancedPrompt

func BuildEnhancedPrompt(ctx *Context) string

func CheckHasChanges

func CheckHasChanges() (bool, error)

func CleanupBranch

func CleanupBranch(branchName, mainBranch string)

func CleanupWorktree

func CleanupWorktree(ctx *Context)

func CommitAndCreatePR

func CommitAndCreatePR(ctx *Context, branchName, mainBranch string, display func() string) error

func CommitOnCurrentBranch

func CommitOnCurrentBranch(ctx *Context, display func() string) error

func CreateIterationBranch

func CreateIterationBranch(ctx *Context, iteration int, display func() string) (mainBranch, branchName string, err error)

func DetectGitHubRepo

func DetectGitHubRepo() (owner, repo string, err error)

func DetectProviderFromRemote added in v1.0.49

func DetectProviderFromRemote(remoteURL string) string

DetectProviderFromRemote 从 git remote URL 检测仓库提供商

func ErrUnknownProvider added in v1.0.49

func ErrUnknownProvider(name string) error

ErrUnknownProvider 返回未知提供商错误

func ExecuteCallbacks added in v1.0.49

func ExecuteCallbacks(agentCtx *Context, mainErr error)

func FormatDuration

func FormatDuration(d time.Duration) string

func GenerateRandomHash

func GenerateRandomHash() string

func GetCurrentBranch

func GetCurrentBranch() string

func GetFailedRunID

func GetFailedRunID(ctx *Context, prNumber string) (string, error)

func GetHeadSHA added in v1.0.50

func GetHeadSHA() (string, error)

func GetIterationDisplay

func GetIterationDisplay(iteration, maxRuns, extraIterations int) func() string

func ListWorktrees

func ListWorktrees() error

func MergePRAndCleanup

func MergePRAndCleanup(ctx *Context, prNumber, branchName, mainBranch string, display func() string) error

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

func Run

func Run(ctx *Context) error

func RunCIFixIteration

func RunCIFixIteration(ctx *Context, prNumber string, display func() string, attempt int) error

func RunReviewerIteration

func RunReviewerIteration(ctx *Context, display func() string) error

func SetupRepoProvider added in v1.0.50

func SetupRepoProvider(ctx *Context, providerName, repoID string, opts ProviderOptions) error

func SetupWorktree

func SetupWorktree(ctx *Context) error

func ValidateRequirements

func ValidateRequirements(ctx *Context) error

func WaitForPRChecks

func WaitForPRChecks(ctx *Context, prNumber string, display func() string) bool

Types

type AIBackend added in v1.0.49

type AIBackend interface {
	Validate() error
	RunIteration(ctx *Context, prompt string, display func() string) (*BackendResult, error)
	RunCommit(ctx *Context, prompt string) error
	Name() string
}

func NewBackend added in v1.0.49

func NewBackend(name string) (AIBackend, error)

type BackendResult added in v1.0.49

type BackendResult struct {
	Type         string  `json:"type"`
	Result       string  `json:"result"`
	IsError      bool    `json:"is_error"`
	TotalCostUSD float64 `json:"total_cost_usd"`
}

type ClaudeCodeBackend added in v1.0.49

type ClaudeCodeBackend struct{}

func (*ClaudeCodeBackend) Name added in v1.0.49

func (b *ClaudeCodeBackend) Name() string

func (*ClaudeCodeBackend) RunCommit added in v1.0.49

func (b *ClaudeCodeBackend) RunCommit(ctx *Context, prompt string) error

func (*ClaudeCodeBackend) RunIteration added in v1.0.49

func (b *ClaudeCodeBackend) RunIteration(ctx *Context, prompt string, display func() string) (*BackendResult, error)

func (*ClaudeCodeBackend) Validate added in v1.0.49

func (b *ClaudeCodeBackend) Validate() error

type CodexBackend added in v1.0.49

type CodexBackend struct{}

func (*CodexBackend) Name added in v1.0.49

func (b *CodexBackend) Name() string

func (*CodexBackend) RunCommit added in v1.0.49

func (b *CodexBackend) RunCommit(ctx *Context, prompt string) error

func (*CodexBackend) RunIteration added in v1.0.49

func (b *CodexBackend) RunIteration(ctx *Context, prompt string, display func() string) (*BackendResult, error)

func (*CodexBackend) Validate added in v1.0.49

func (b *CodexBackend) Validate() error

type Context

type Context struct {
	Prompt              string
	Model               string
	MaxRuns             int
	MaxCost             float64
	MaxDuration         time.Duration
	EnableCommits       bool
	EnableBranches      bool
	BranchPrefix        string
	MergeStrategy       string
	NotesFile           string
	DryRun              bool
	Debug               bool
	CompletionSignal    string
	CompletionThreshold int
	ReviewPrompt        string
	CIRetryEnabled      bool
	CIRetryMax          int
	WorktreeName        string
	WorktreeBaseDir     string
	CleanupWorktree     bool
	Backend             AIBackend
	RunContext          context.Context
	RunCancel           context.CancelFunc

	// 仓库提供商抽象
	RepoProvider RepositoryProvider
	RepoInfo     *RepositoryInfo

	SuccessfulIterations int
	ErrorCount           int
	ExtraIterations      int
	TotalCost            float64
	CompletionCount      int
	StartTime            time.Time

	OnComplete string
	OnError    string
	OnFinish   string
}

type CoolProvider added in v1.0.49

type CoolProvider struct {
	Endpoint string
	// contains filtered or unexported fields
}

func (*CoolProvider) ClosePullRequest added in v1.0.49

func (p *CoolProvider) ClosePullRequest(ctx *Context, prID string, deleteBranch bool) error

func (*CoolProvider) CreatePullRequest added in v1.0.49

func (p *CoolProvider) CreatePullRequest(ctx *Context, opts *PRCreateOptions) (*PullRequestInfo, error)

func (*CoolProvider) DetectFromGit added in v1.0.49

func (p *CoolProvider) DetectFromGit() (*RepositoryInfo, error)

func (*CoolProvider) GetFailedWorkflowRun added in v1.0.49

func (p *CoolProvider) GetFailedWorkflowRun(ctx *Context, prID string) (string, error)

func (*CoolProvider) GetPRChecks added in v1.0.49

func (p *CoolProvider) GetPRChecks(ctx *Context, prID string) ([]PRCheckResult, error)

func (*CoolProvider) GetPRReviewStatus added in v1.0.49

func (p *CoolProvider) GetPRReviewStatus(ctx *Context, prID string) (*PRReviewStatus, error)

func (*CoolProvider) GetPRStatus added in v1.0.49

func (p *CoolProvider) GetPRStatus(ctx *Context, prID string) (*PRStatus, error)

func (*CoolProvider) MergePullRequest added in v1.0.49

func (p *CoolProvider) MergePullRequest(ctx *Context, prID string, strategy MergeStrategy) error

func (*CoolProvider) Name added in v1.0.49

func (p *CoolProvider) Name() string

func (*CoolProvider) SupportsBranches added in v1.0.49

func (p *CoolProvider) SupportsBranches() bool

func (*CoolProvider) SupportsCI added in v1.0.49

func (p *CoolProvider) SupportsCI() bool

func (*CoolProvider) UpdatePRBranch added in v1.0.49

func (p *CoolProvider) UpdatePRBranch(ctx *Context, prID string) error

func (*CoolProvider) Validate added in v1.0.49

func (p *CoolProvider) Validate(ctx *Context) error

type GitHubProvider added in v1.0.49

type GitHubProvider struct{}

func (*GitHubProvider) ClosePullRequest added in v1.0.49

func (p *GitHubProvider) ClosePullRequest(ctx *Context, prID string, deleteBranch bool) error

func (*GitHubProvider) CreatePullRequest added in v1.0.49

func (p *GitHubProvider) CreatePullRequest(ctx *Context, opts *PRCreateOptions) (*PullRequestInfo, error)

func (*GitHubProvider) DetectFromGit added in v1.0.49

func (p *GitHubProvider) DetectFromGit() (*RepositoryInfo, error)

func (*GitHubProvider) GetFailedWorkflowRun added in v1.0.49

func (p *GitHubProvider) GetFailedWorkflowRun(ctx *Context, prID string) (string, error)

func (*GitHubProvider) GetPRChecks added in v1.0.49

func (p *GitHubProvider) GetPRChecks(ctx *Context, prID string) ([]PRCheckResult, error)

func (*GitHubProvider) GetPRReviewStatus added in v1.0.49

func (p *GitHubProvider) GetPRReviewStatus(ctx *Context, prID string) (*PRReviewStatus, error)

func (*GitHubProvider) GetPRStatus added in v1.0.49

func (p *GitHubProvider) GetPRStatus(ctx *Context, prID string) (*PRStatus, error)

func (*GitHubProvider) MergePullRequest added in v1.0.49

func (p *GitHubProvider) MergePullRequest(ctx *Context, prID string, strategy MergeStrategy) error

func (*GitHubProvider) Name added in v1.0.49

func (p *GitHubProvider) Name() string

func (*GitHubProvider) SupportsBranches added in v1.0.49

func (p *GitHubProvider) SupportsBranches() bool

func (*GitHubProvider) SupportsCI added in v1.0.49

func (p *GitHubProvider) SupportsCI() bool

func (*GitHubProvider) UpdatePRBranch added in v1.0.49

func (p *GitHubProvider) UpdatePRBranch(ctx *Context, prID string) error

func (*GitHubProvider) Validate added in v1.0.49

func (p *GitHubProvider) Validate(ctx *Context) error

type MergeStrategy added in v1.0.49

type MergeStrategy string

MergeStrategy 合并策略

const (
	MergeStrategySquash MergeStrategy = "squash"
	MergeStrategyMerge  MergeStrategy = "merge"
	MergeStrategyRebase MergeStrategy = "rebase"
)

type OpencodeBackend added in v1.0.49

type OpencodeBackend struct{}

func (*OpencodeBackend) Name added in v1.0.49

func (b *OpencodeBackend) Name() string

func (*OpencodeBackend) RunCommit added in v1.0.49

func (b *OpencodeBackend) RunCommit(ctx *Context, prompt string) error

func (*OpencodeBackend) RunIteration added in v1.0.49

func (b *OpencodeBackend) RunIteration(ctx *Context, prompt string, display func() string) (*BackendResult, error)

func (*OpencodeBackend) Validate added in v1.0.49

func (b *OpencodeBackend) Validate() error

type PRCheckResult

type PRCheckResult struct {
	State  string `json:"state"`
	Bucket string `json:"bucket"`
}

type PRCreateOptions added in v1.0.49

type PRCreateOptions struct {
	Title        string
	Body         string
	SourceBranch string
	TargetBranch string
}

PRCreateOptions PR 创建选项

type PRInfo

type PRInfo struct {
	ReviewDecision string `json:"reviewDecision"`
	ReviewRequests []struct {
		Login string `json:"login"`
	} `json:"reviewRequests"`
	State      string `json:"state"`
	HeadRefOid string `json:"headRefOid"`
}

type PRReviewStatus added in v1.0.49

type PRReviewStatus struct {
	ReviewDecision string   // APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED, ""
	ReviewRequests []string // 待审查者列表
}

PRReviewStatus PR 审查状态

type PRStatus added in v1.0.49

type PRStatus struct {
	State     string // open, merged, closed
	CIStatus  string // pending, success, failure
	CIRunID   string
	ChecksURL string
}

PRStatus PR 状态

type ProviderOptions added in v1.0.49

type ProviderOptions struct {
	Endpoint string // API 端点 (可选,有默认值)
	APIKey   string // API Key (可选)
}

ProviderOptions 提供商初始化选项

type PullRequestInfo added in v1.0.49

type PullRequestInfo struct {
	ID     string
	Number int
	URL    string
}

PullRequestInfo PR 信息

type RepositoryInfo added in v1.0.49

type RepositoryInfo struct {
	Provider string // github, cool, etc.
	Owner    string // 所有者/组织
	Repo     string // 仓库名(完整路径,如 "owner/repo")
}

RepositoryInfo 仓库信息

type RepositoryProvider added in v1.0.49

type RepositoryProvider interface {
	// Name 返回提供商名称 (github, cool, etc.)
	Name() string

	// Validate 验证配置和环境
	Validate(ctx *Context) error

	// DetectFromGit 从 git remote 自动检测仓库信息
	DetectFromGit() (*RepositoryInfo, error)

	// CreatePullRequest 创建 PR/MR
	CreatePullRequest(ctx *Context, opts *PRCreateOptions) (*PullRequestInfo, error)

	// MergePullRequest 合并 PR
	MergePullRequest(ctx *Context, prID string, strategy MergeStrategy) error

	// GetPRStatus 获取 PR 的 CI 状态
	GetPRStatus(ctx *Context, prID string) (*PRStatus, error)

	// GetPRChecks 获取 PR 检查项详细信息
	GetPRChecks(ctx *Context, prID string) ([]PRCheckResult, error)

	// GetPRReviewStatus 获取 PR 审查状态
	GetPRReviewStatus(ctx *Context, prID string) (*PRReviewStatus, error)

	// UpdatePRBranch 更新 PR 分支与目标分支同步
	UpdatePRBranch(ctx *Context, prID string) error

	// ClosePullRequest 关闭 PR
	ClosePullRequest(ctx *Context, prID string, deleteBranch bool) error

	// GetFailedWorkflowRun 获取 PR 的失败 workflow run ID
	GetFailedWorkflowRun(ctx *Context, prID string) (string, error)

	// SupportsBranches 是否支持分支工作流
	SupportsBranches() bool

	// SupportsCI 是否支持 CI 集成
	SupportsCI() bool
}

RepositoryProvider 定义仓库操作的抽象接口

func NewRepositoryProvider added in v1.0.49

func NewRepositoryProvider(providerName string, opts ProviderOptions) (RepositoryProvider, error)

NewRepositoryProvider 创建仓库提供商实例

type WorkflowRun

type WorkflowRun struct {
	DatabaseId int `json:"databaseId"`
}

Jump to

Keyboard shortcuts

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