75 lines
2.2 KiB
Go
75 lines
2.2 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
|
|
// Scope classifies the tool's concurrency behavior for parallel dispatch:
|
|
// "read" — path-scoped read; never conflicts (always parallelizable)
|
|
// "write" — path-scoped write; conflicts only on same file path
|
|
// "global" — full serialization barrier; runs alone
|
|
// Empty defaults to inference: "write" if tool has a path arg, else "global".
|
|
Scope string
|
|
// 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
|
|
}
|