tools: consolidate into shell.go, tool.go, skill.go

One file per domain, all related handlers together.
This commit is contained in:
Levi Neely 2026-07-29 23:20:01 +02:00
parent a21c256efa
commit cadcb62fcd
8 changed files with 160 additions and 196 deletions

83
tools/skill.go Normal file
View File

@ -0,0 +1,83 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"strings"
"ollie/toolsrv"
)
// SkillList lists all available skills from the global registry.
func SkillList(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.SkillsRegistry()
if reg == nil {
return "", fmt.Errorf("skill_list: no skills registry available")
}
summaries := reg.Summaries()
if len(summaries) == 0 {
return "(no skills found)", nil
}
var out strings.Builder
for _, s := range summaries {
out.WriteString(s.Name)
if s.Description != "" {
out.WriteString(" — ")
out.WriteString(s.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}
// SkillLoad loads a skill into the current session.
func SkillLoad(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Name string `json:"name"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("skill_load: bad args: %w", err)
}
if a.Name == "" {
return "", fmt.Errorf("skill_load: name is required")
}
reg := srv.SkillsRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "", fmt.Errorf("skill_load: no session registry")
}
if err := reg.Load(sid, a.Name); err != nil {
return "", fmt.Errorf("skill_load: %w", err)
}
content, err := reg.SkillContent(a.Name)
if err != nil {
return "", fmt.Errorf("skill_load: %w", err)
}
injectMsg := fmt.Sprintf("[system: loaded skill %s]\n\n%s", a.Name, content)
srv.InjectContent(injectMsg)
return fmt.Sprintf("loaded: %s (%d bytes)", a.Name, len(content)), nil
}
// SkillActive lists skills currently loaded in this session.
func SkillActive(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.SkillsRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "(no skills loaded)", nil
}
loaded := reg.Loaded(sid)
if len(loaded) == 0 {
return "(no skills loaded)", nil
}
var out strings.Builder
for _, s := range loaded {
out.WriteString(s.Name)
if s.Description != "" {
out.WriteString(" — ")
out.WriteString(s.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}

View File

@ -1,32 +0,0 @@
package tools
import (
"context"
"encoding/json"
"strings"
"ollie/toolsrv"
)
// SkillActive lists skills currently loaded in this session.
func SkillActive(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.SkillsRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "(no skills loaded)", nil
}
loaded := reg.Loaded(sid)
if len(loaded) == 0 {
return "(no skills loaded)", nil
}
var out strings.Builder
for _, s := range loaded {
out.WriteString(s.Name)
if s.Description != "" {
out.WriteString(" — ")
out.WriteString(s.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}

View File

@ -1,32 +0,0 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"strings"
"ollie/toolsrv"
)
// SkillList lists all available skills from the global registry.
func SkillList(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.SkillsRegistry()
if reg == nil {
return "", fmt.Errorf("skill_list: no skills registry available")
}
summaries := reg.Summaries()
if len(summaries) == 0 {
return "(no skills found)", nil
}
var out strings.Builder
for _, s := range summaries {
out.WriteString(s.Name)
if s.Description != "" {
out.WriteString(" — ")
out.WriteString(s.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}

View File

@ -1,37 +0,0 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"ollie/toolsrv"
)
// SkillLoad loads a skill into the current session.
func SkillLoad(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Name string `json:"name"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("skill_load: bad args: %w", err)
}
if a.Name == "" {
return "", fmt.Errorf("skill_load: name is required")
}
reg := srv.SkillsRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "", fmt.Errorf("skill_load: no session registry")
}
if err := reg.Load(sid, a.Name); err != nil {
return "", fmt.Errorf("skill_load: %w", err)
}
content, err := reg.SkillContent(a.Name)
if err != nil {
return "", fmt.Errorf("skill_load: %w", err)
}
injectMsg := fmt.Sprintf("[system: loaded skill %s]\n\n%s", a.Name, content)
srv.InjectContent(injectMsg)
return fmt.Sprintf("loaded: %s (%d bytes)", a.Name, len(content)), nil
}

77
tools/tool.go Normal file
View File

@ -0,0 +1,77 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"strings"
"ollie/toolsrv"
)
// ToolList lists all available tools from the global registry.
func ToolList(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.ToolRegistry()
if reg == nil {
return "", fmt.Errorf("tool_list: no registry available")
}
summaries := reg.Summaries()
if len(summaries) == 0 {
return "(no tools found)", nil
}
var out strings.Builder
for _, s := range summaries {
out.WriteString(s.Name)
if s.Description != "" {
out.WriteString(" — ")
out.WriteString(s.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}
// ToolLoad loads a tool into the current session.
func ToolLoad(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Name string `json:"name"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("tool_load: bad args: %w", err)
}
if a.Name == "" {
return "", fmt.Errorf("tool_load: name is required")
}
reg := srv.ToolRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "", fmt.Errorf("tool_load: no session registry")
}
if err := reg.Load(sid, a.Name); err != nil {
return "", fmt.Errorf("tool_load: %w", err)
}
return fmt.Sprintf("loaded: %s", a.Name), nil
}
// ToolActive lists tools currently loaded (promoted) in this session.
func ToolActive(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.ToolRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "(no tools loaded)", nil
}
loaded := reg.Loaded(sid)
if len(loaded) == 0 {
return "(no tools loaded)", nil
}
var out strings.Builder
for _, t := range loaded {
out.WriteString(t.Name)
if t.Description != "" {
out.WriteString(" — ")
out.WriteString(t.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}

View File

@ -1,32 +0,0 @@
package tools
import (
"context"
"encoding/json"
"strings"
"ollie/toolsrv"
)
// ToolActive lists tools currently loaded (promoted) in this session.
func ToolActive(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.ToolRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "(no tools loaded)", nil
}
loaded := reg.Loaded(sid)
if len(loaded) == 0 {
return "(no tools loaded)", nil
}
var out strings.Builder
for _, t := range loaded {
out.WriteString(t.Name)
if t.Description != "" {
out.WriteString(" — ")
out.WriteString(t.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}

View File

@ -1,32 +0,0 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"strings"
"ollie/toolsrv"
)
// ToolList lists all available tools from the global registry.
func ToolList(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
reg := srv.ToolRegistry()
if reg == nil {
return "", fmt.Errorf("tool_list: no registry available")
}
summaries := reg.Summaries()
if len(summaries) == 0 {
return "(no tools found)", nil
}
var out strings.Builder
for _, s := range summaries {
out.WriteString(s.Name)
if s.Description != "" {
out.WriteString(" — ")
out.WriteString(s.Description)
}
out.WriteString("\n")
}
return strings.TrimRight(out.String(), "\n"), nil
}

View File

@ -1,31 +0,0 @@
package tools
import (
"context"
"encoding/json"
"fmt"
"ollie/toolsrv"
)
// ToolLoad loads a tool into the current session.
func ToolLoad(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Name string `json:"name"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("tool_load: bad args: %w", err)
}
if a.Name == "" {
return "", fmt.Errorf("tool_load: name is required")
}
reg := srv.ToolRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "", fmt.Errorf("tool_load: no session registry")
}
if err := reg.Load(sid, a.Name); err != nil {
return "", fmt.Errorf("tool_load: %w", err)
}
return fmt.Sprintf("loaded: %s", a.Name), nil
}