This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/execute/tier.go

77 lines
2.1 KiB
Go

package execute
import (
"encoding/json"
"ollie/tools"
"strings"
)
// ResultTier implements tools.TierClassifier. Looks up the tool's cached tier
// from the registry; falls back to reading the script on disk.
func (e *Server) ResultTier(name string) string {
if e.toolRegistry != nil && e.sessionID != "" {
if info, ok := e.toolRegistry.Lookup(e.sessionID, name); ok && info.Tier != "" {
return info.Tier
}
}
code, err := tools.ReadTool(name)
if err != nil {
return "hot"
}
return detectTier(code)
}
// ResultTierArgs classifies the tier using both the outer tool name and its
// arguments. For shell, it returns warm. For promoted tools, it
// delegates to ResultTier.
func (e *Server) ResultTierArgs(name string, args json.RawMessage) string {
switch name {
case "shell":
return "warm"
default:
return e.ResultTier(name)
}
}
// IsParallelRead implements tools.ParallelClassifier. Returns true when the
// named tool script is ReadOnly (ollie:parallel read annotation).
// Checks the registry cache first; falls back to reading the script.
func (e *Server) IsParallelRead(name string) bool {
if e.toolRegistry != nil && e.sessionID != "" {
if info, ok := e.toolRegistry.Lookup(e.sessionID, name); ok {
return info.ReadOnly
}
}
code, err := tools.ReadTool(name)
if err != nil {
return false
}
for _, line := range strings.SplitN(code, "\n", 11) {
if strings.Contains(line, "ollie:parallel read") {
return true
}
}
return false
}
// detectTier scans the first 10 lines of a tool script for an
// "ollie:tier" annotation. Fallback when a tool isn't in the registry.
func detectTier(code string) string {
for _, line := range strings.SplitN(code, "\n", 11) {
idx := strings.Index(line, "ollie:tier")
if idx < 0 {
continue
}
rest := strings.TrimSpace(line[idx+len("ollie:tier"):])
switch {
case rest == "cold" || strings.HasPrefix(rest, "cold "):
return "cold"
case rest == "warm" || strings.HasPrefix(rest, "warm "):
return "warm"
case rest == "hot" || strings.HasPrefix(rest, "hot "):
return "hot"
}
}
return "hot"
}