55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package execute
|
|
|
|
import "strings"
|
|
|
|
// defaultColdTools are tools whose results are consumed immediately and don't
|
|
// need to persist verbatim in the message history.
|
|
var defaultColdTools = map[string]string{
|
|
"file_read": "cold",
|
|
"memory_recall": "cold",
|
|
"web_fetch": "cold",
|
|
"web_search": "cold",
|
|
"lsp_definition": "cold",
|
|
"lsp_references": "cold",
|
|
"lsp_hover": "cold",
|
|
}
|
|
|
|
// ResultTier implements tools.TierClassifier. Checks the built-in table first,
|
|
// then falls back to the script's "ollie:tier" annotation.
|
|
func (e *Server) ResultTier(name string) string {
|
|
if tier, ok := defaultColdTools[name]; ok {
|
|
return tier
|
|
}
|
|
code, err := ReadTool(name)
|
|
if err != nil {
|
|
return "hot"
|
|
}
|
|
return detectTier(code)
|
|
}
|
|
|
|
// detectTier scans the first 10 lines of a tool script for an
|
|
// "ollie:tier" annotation. Matches "ollie:tier hot", "ollie:tier warm",
|
|
// or "ollie:tier cold" anywhere in the line.
|
|
func detectTier(code string) string {
|
|
lines := strings.SplitN(code, "\n", 11)
|
|
if len(lines) > 10 {
|
|
lines = lines[:10]
|
|
}
|
|
for _, line := range lines {
|
|
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"
|
|
}
|