MCPcopy Create free account
hub / github.com/astercloud/aster / LoadGlobalRules

Method LoadGlobalRules

pkg/memory/rules/manager.go:71–102  ·  view source on GitHub ↗

LoadGlobalRules 加载全局规则

(ctx context.Context)

Source from the content-addressed store, hash-verified

69
70// LoadGlobalRules 加载全局规则
71func (m *Manager) LoadGlobalRules(ctx context.Context) error {
72 m.mu.Lock()
73 defer m.mu.Unlock()
74
75 // 从文件加载
76 if m.config.GlobalRulesPath != "" {
77 rules, err := m.loadRulesFromFile(m.config.GlobalRulesPath, ScopeGlobal)
78 if err != nil {
79 // 文件不存在不是错误
80 if !os.IsNotExist(err) {
81 return fmt.Errorf("load global rules failed: %w", err)
82 }
83 } else {
84 for _, r := range rules {
85 m.ruleSet.AddGlobalRule(r)
86 }
87 }
88 }
89
90 // 使用自定义加载器
91 for _, loader := range m.loaders {
92 rules, err := loader.LoadGlobalRules(ctx)
93 if err != nil {
94 return fmt.Errorf("loader %T failed: %w", loader, err)
95 }
96 for _, r := range rules {
97 m.ruleSet.AddGlobalRule(r)
98 }
99 }
100
101 return nil
102}
103
104// LoadProjectRules 加载项目规则
105func (m *Manager) LoadProjectRules(ctx context.Context, projectID string) error {

Callers

nothing calls this directly

Calls 3

loadRulesFromFileMethod · 0.95
LoadGlobalRulesMethod · 0.65
AddGlobalRuleMethod · 0.45

Tested by

no test coverage detected