package tools import ( "sync" ) // registry is the default implementation of Registry. type registry struct { mu sync.RWMutex tools map[string]Tool order []string } // NewRegistry returns a new empty registry. func NewRegistry() Registry { return ®istry{ tools: make(map[string]Tool), } } func (r *registry) Register(t Tool) error { r.mu.Lock() defer r.mu.Unlock() if _, exists := r.tools[t.Name]; exists { return ErrDuplicateTool } r.tools[t.Name] = t r.order = append(r.order, t.Name) return nil } func (r *registry) Get(name string) (Tool, bool) { r.mu.RLock() defer r.mu.RUnlock() t, ok := r.tools[name] return t, ok } func (r *registry) List() []Tool { r.mu.RLock() defer r.mu.RUnlock() out := make([]Tool, len(r.order)) for i, name := range r.order { out[i] = r.tools[name] } return out } func (r *registry) Filter(predicate func(Tool) bool) []Tool { r.mu.RLock() defer r.mu.RUnlock() var result []Tool for _, name := range r.order { t := r.tools[name] if predicate(t) { result = append(result, t) } } return result }