rules

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package rules 提供规则管理系统 支持 Global(全局)和 Project(项目)两个级别的规则

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader interface {
	// LoadGlobalRules 加载全局规则
	LoadGlobalRules(ctx context.Context) ([]*Rule, error)

	// LoadProjectRules 加载项目规则
	LoadProjectRules(ctx context.Context, projectID string) ([]*Rule, error)
}

Loader 规则加载器接口

type Manager

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

Manager 规则管理器

func NewManager

func NewManager(config *ManagerConfig) *Manager

NewManager 创建规则管理器

func (*Manager) AddGlobalRule

func (m *Manager) AddGlobalRule(rule *Rule)

AddGlobalRule 添加全局规则

func (*Manager) AddProjectRule

func (m *Manager) AddProjectRule(projectID string, rule *Rule)

AddProjectRule 添加项目规则

func (*Manager) GetRulesContent

func (m *Manager) GetRulesContent(projectID string) string

GetRulesContent 获取规则内容(用于 AI 上下文注入)

func (*Manager) GetRulesForProject

func (m *Manager) GetRulesForProject(projectID string) []*Rule

GetRulesForProject 获取项目的所有规则

func (*Manager) LoadGlobalRules

func (m *Manager) LoadGlobalRules(ctx context.Context) error

LoadGlobalRules 加载全局规则

func (*Manager) LoadProjectRules

func (m *Manager) LoadProjectRules(ctx context.Context, projectID string) error

LoadProjectRules 加载项目规则

func (*Manager) RegisterLoader

func (m *Manager) RegisterLoader(loader Loader)

RegisterLoader 注册规则加载器

type ManagerConfig

type ManagerConfig struct {
	// GlobalRulesPath 全局规则文件路径
	GlobalRulesPath string

	// ProjectBasePath 项目基础路径
	ProjectBasePath string

	// ProjectRuleFile 项目规则文件名(默认 AGENTS.md)
	ProjectRuleFile string

	// AutoReload 是否自动重新加载
	AutoReload bool
}

ManagerConfig 管理器配置

func DefaultManagerConfig

func DefaultManagerConfig() *ManagerConfig

DefaultManagerConfig 默认配置

type Rule

type Rule struct {
	// ID 规则 ID
	ID string `json:"id"`

	// Scope 作用域
	Scope Scope `json:"scope"`

	// Title 标题
	Title string `json:"title"`

	// Content 规则内容
	Content string `json:"content"`

	// Source 来源(AGENTS.md, user_config, system)
	Source string `json:"source"`

	// SourcePath 来源路径(如文件路径)
	SourcePath string `json:"source_path,omitempty"`

	// Priority 优先级(数字越大优先级越高)
	Priority int `json:"priority"`

	// Enabled 是否启用
	Enabled bool `json:"enabled"`

	// Tags 标签
	Tags []string `json:"tags,omitempty"`

	// Metadata 元数据
	Metadata map[string]any `json:"metadata,omitempty"`

	// CreatedAt 创建时间
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt 更新时间
	UpdatedAt time.Time `json:"updated_at"`
}

Rule 规则

func NewRule

func NewRule(scope Scope, title, content string) *Rule

NewRule 创建新规则

type RuleSet

type RuleSet struct {
	// GlobalRules 全局规则
	GlobalRules []*Rule `json:"global_rules"`

	// ProjectRules 项目规则(key: projectID)
	ProjectRules map[string][]*Rule `json:"project_rules"`
}

RuleSet 规则集

func NewRuleSet

func NewRuleSet() *RuleSet

NewRuleSet 创建规则集

func (*RuleSet) AddGlobalRule

func (rs *RuleSet) AddGlobalRule(rule *Rule)

AddGlobalRule 添加全局规则

func (*RuleSet) AddProjectRule

func (rs *RuleSet) AddProjectRule(projectID string, rule *Rule)

AddProjectRule 添加项目规则

func (*RuleSet) GetRulesContent

func (rs *RuleSet) GetRulesContent(projectID string) string

GetRulesContent 获取规则内容(用于注入 AI 上下文)

func (*RuleSet) GetRulesForProject

func (rs *RuleSet) GetRulesForProject(projectID string) []*Rule

GetRulesForProject 获取项目的所有规则(包含全局规则)

type Scope

type Scope string

Scope 规则作用域

const (
	// ScopeGlobal 全局规则(用户级,跨项目)
	ScopeGlobal Scope = "global"
	// ScopeProject 项目规则(项目级)
	ScopeProject Scope = "project"
)

Jump to

Keyboard shortcuts

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