chore: delete code no binary or test reaches

This commit is contained in:
sam committed 2026-10-17 10:14:26 +11:00
1 parent 7986ccb3f7
commit 01acb97f96
34 files changed
+1 -1483

No files matched your search

-105
View File
@@ -1,105 +0,0 @@
package tools
import (
"sync"
"time"
)
// AvailabilityCache wraps a [CheckFn] with TTL-based result caching.
//
// Positive results (tool is available) are cached for the TTL duration.
// Negative results (tool is unavailable) are cached for the failure
// grace period. A nil check function means "always available" -- Check
// returns true immediately with no caching overhead.
//
// All methods are safe for concurrent use.
type AvailabilityCache struct {
TTL time.Duration
FailureGracePeriod time.Duration
check CheckFn
mu sync.Mutex
lastResult bool
checkedAt time.Time
}
// NewAvailabilityCache creates an [AvailabilityCache] wrapping the given
// check function. If check is nil, Check always returns true (the tool
// is permanently available and no caching is needed).
//
// Typical values: TTL=30s for positive results, FailureGracePeriod=60s
// for negative results (avoid churn when a dependency is temporarily down).
func NewAvailabilityCache(check CheckFn, ttl, failureGrace time.Duration) *AvailabilityCache {
return &AvailabilityCache{
TTL: ttl,
FailureGracePeriod: failureGrace,
check: check,
}
}
// Check reports whether the tool is available. It returns the cached
// result when the cache is still fresh; otherwise it re-evaluates the
// underlying check function.
//
// When the underlying check returns true (available), the result is
// cached for c.TTL. When it returns false (unavailable), the result is
// cached for c.FailureGracePeriod -- this prevents tight re-check loops
// while a dependency is temporarily down.
func (c *AvailabilityCache) Check() bool {
if c.check == nil {
return true
}
c.mu.Lock()
defer c.mu.Unlock()
now := time.Now()
cacheDuration := c.TTL
if !c.lastResult {
cacheDuration = c.FailureGracePeriod
}
if c.checkedAt.IsZero() || now.Sub(c.checkedAt) >= cacheDuration {
c.lastResult = c.check()
c.checkedAt = now
}
return c.lastResult
}
// Invalidate forces the next call to Check to bypass the cache and
// re-evaluate the underlying check function.
func (c *AvailabilityCache) Invalidate() {
c.mu.Lock()
c.checkedAt = time.Time{}
c.mu.Unlock()
}
// LastChecked reports when the cache was last refreshed. A zero time
// means the cache has never been evaluated.
func (c *AvailabilityCache) LastChecked() time.Time {
c.mu.Lock()
defer c.mu.Unlock()
return c.checkedAt
}
// CachedAvailable returns the most recent cached result without
// re-evaluating the check function. For tools with a nil check,
// this always returns true.
func (c *AvailabilityCache) CachedAvailable() bool {
if c.check == nil {
return true
}
c.mu.Lock()
defer c.mu.Unlock()
return c.lastResult
}
// NewAvailabilityCacheFromEntry is a convenience constructor that creates
// an [AvailabilityCache] from a [ToolEntry]'s CheckFn using the given TTL
// and failure grace period. When the entry has a nil CheckFn the returned
// cache reports always-available.
func NewAvailabilityCacheFromEntry(e ToolEntry, ttl, failureGrace time.Duration) *AvailabilityCache {
return NewAvailabilityCache(e.CheckFn, ttl, failureGrace)
}
-35
View File
@@ -262,18 +262,6 @@ const (
DisclosureBridge
)
// String returns a human-readable representation of the mode.
func (m DisclosureMode) String() string {
switch m {
case DisclosureFull:
return "full"
case DisclosureBridge:
return "bridge"
default:
return "unknown"
}
}
// ContextPressureGate monitors the size of tool schemas relative to the
// LLM context window and dynamically switches between full disclosure
// and bridge-tool mode.
@@ -331,13 +319,6 @@ func (g *ContextPressureGate) Evaluate(tools []ToolEntry) DisclosureMode {
return g.currentMode
}
// Mode returns the current disclosure mode.
func (g *ContextPressureGate) Mode() DisclosureMode {
g.mu.RLock()
defer g.mu.RUnlock()
return g.currentMode
}
// FilterTools returns the set of tools that should be disclosed given the
// current mode. In full mode, all tools are returned. In bridge mode, only
// bridge tools and always-visible tools are returned.
@@ -373,22 +354,6 @@ func (g *ContextPressureGate) FilterTools(reg *Registry) []ToolEntry {
return filtered
}
// SetAlwaysVisible marks tools that are always visible regardless of mode.
func (g *ContextPressureGate) SetAlwaysVisible(names ...string) {
g.mu.Lock()
defer g.mu.Unlock()
for _, name := range names {
g.AlwaysVisible[name] = true
}
}
// Reset returns the gate to full disclosure mode.
func (g *ContextPressureGate) Reset() {
g.mu.Lock()
defer g.mu.Unlock()
g.currentMode = DisclosureFull
}
// alwaysVisibleCopy returns a copy of the always-visible set.
func (g *ContextPressureGate) alwaysVisibleCopy() map[string]bool {
out := make(map[string]bool, len(g.AlwaysVisible))