71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
// registry.go - Tool discovery and shared types.
|
|
package toolsrv
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"ollie/paths"
|
|
)
|
|
|
|
// ToolInfo describes a tool provided by a server.
|
|
type ToolInfo struct {
|
|
Server string
|
|
Name string
|
|
Description string
|
|
InputSchema json.RawMessage
|
|
// Prompt is the usage documentation for this tool, extracted from
|
|
// the script's ollie:prompt block. Included in the system prompt.
|
|
Prompt string
|
|
// Tier is the retention tier: "hot", "warm", or "cold". Parsed from
|
|
// the script's ollie:tier annotation. Empty defaults to "hot".
|
|
Tier string
|
|
// ReadOnly is true when the tool carries an "ollie:parallel read" annotation.
|
|
ReadOnly bool
|
|
// OutputFormat is the source-fence language for tool output. Empty means plaintext.
|
|
OutputFormat string
|
|
// ResetsCounter is true for action-oriented tools (file_write, lsp_rename, etc.)
|
|
// that indicate active progress rather than passive research. When true, the
|
|
// agent loop resets its step counter, allowing continued work without hitting
|
|
// the soft step-budget guardrail.
|
|
ResetsCounter bool
|
|
}
|
|
|
|
// ToolsPath returns ~/.config/ollie/tools.
|
|
func ToolsPath() string {
|
|
return paths.CfgDir() + "/tools"
|
|
}
|
|
|
|
// DiscoverTools scans the tools directory for .meta files and returns
|
|
// metadata for all tools.
|
|
func DiscoverTools() []ToolInfo {
|
|
dir := ToolsPath()
|
|
entries, err := os.ReadDir(dir)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
var infos []ToolInfo
|
|
for _, e := range entries {
|
|
if e.IsDir() || !strings.HasSuffix(e.Name(), ".meta") {
|
|
continue
|
|
}
|
|
name := strings.TrimSuffix(e.Name(), ".meta")
|
|
data, err := os.ReadFile(filepath.Join(dir, e.Name()))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
var m MetaFile
|
|
if err := json.Unmarshal(data, &m); err != nil {
|
|
continue
|
|
}
|
|
info := ToolInfoFromMeta(name, &m)
|
|
if info.Name == "" {
|
|
continue // no variant matched — tool unavailable on this host
|
|
}
|
|
infos = append(infos, info)
|
|
}
|
|
return infos
|
|
}
|