v0.29.1 d92a60f

tool.go RawHistoryFolder

1package skills
2
3import (
4	"context"
5	"encoding/json"
6	"fmt"
7	"sync"
8
9	"github.com/bnema/zut/packages/core"
10	"github.com/bnema/zut/packages/provider"
11)
12
13// Tool implements core.Tool, exposing a `skill` tool the LLM can call
14// to load the body of a discovered skill on demand. The system-prompt
15// addendum lists the available names; this tool returns the full
16// markdown for the requested one.
17//
18// The list of skills is held behind a mutex so tests / future
19// /reload-skills wiring can swap in a fresh set without races.
20type Tool struct {
21	mu     sync.RWMutex
22	skills []*Skill
23}
24
25// NewTool returns a skill loader tool seeded with the given skills.
26// Pass the slice from Discover().
27func NewTool(skills []*Skill) *Tool { return &Tool{skills: skills} }
28
29// SetSkills atomically replaces the underlying skill set. Used when
30// the user re-runs discovery (e.g. after editing a SKILL.md).
31func (t *Tool) SetSkills(s []*Skill) {
32	t.mu.Lock()
33	t.skills = s
34	t.mu.Unlock()
35}
36
37// Skills returns a snapshot for callers that need to render the
38// current set (e.g. the /skills picker).
39func (t *Tool) Skills() []*Skill {
40	t.mu.RLock()
41	defer t.mu.RUnlock()
42	out := make([]*Skill, len(t.skills))
43	copy(out, t.skills)
44	return out
45}
46
47// ---- core.Tool implementation ----
48
49// Name is the LLM-facing tool name.
50func (*Tool) Name() string { return "skill" }
51
52// Description tells the model what this tool does. Kept blunt so the
53// model reliably uses it instead of guessing what a "skill" is.
54func (*Tool) Description() string {
55	return "Load a named skill's instructions. Use when the user's request matches a skill listed above."
56}
57
58// Schema is one required string parameter: the skill name.
59func (*Tool) Schema() json.RawMessage {
60	return json.RawMessage(`{"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}`)
61}
62
63// Execute returns the markdown body of the requested skill.
64func (t *Tool) Execute(ctx context.Context, args json.RawMessage, progress func(string)) (core.ToolResult, error) {
65	var in struct {
66		Name string `json:"name"`
67	}
68	if err := json.Unmarshal(args, &in); err != nil {
69		return core.ToolResult{
70			IsError: true,
71			Content: []provider.Content{provider.TextBlock{Text: "skill: invalid args: " + err.Error()}},
72		}, nil
73	}
74	if in.Name == "" {
75		return core.ToolResult{
76			IsError: true,
77			Content: []provider.Content{provider.TextBlock{Text: "skill: name is required"}},
78		}, nil
79	}
80
81	t.mu.RLock()
82	s := FindByName(t.skills, in.Name)
83	t.mu.RUnlock()
84	if s == nil {
85		return core.ToolResult{
86			IsError: true,
87			Content: []provider.Content{provider.TextBlock{Text: fmt.Sprintf("skill: no skill named %q (run /skills in zut to see what's available)", in.Name)}},
88		}, nil
89	}
90
91	header := fmt.Sprintf("# Skill: %s\n\n%s\n\n---\n\n", s.Name, s.Description)
92	return core.ToolResult{
93		Content: []provider.Content{provider.TextBlock{Text: header + s.Body}},
94		Details: map[string]any{
95			"skill": s.Name,
96			"path":  s.Path,
97		},
98	}, nil
99}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close