package toolsrv import ( "encoding/json" "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 := 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 := 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" }