blob: 15a4059c044ea4e1eb950e6ecc40f94a7e6388d6 [file] [log] [blame]
Josh Bleecher Snyder74d690e2025-05-14 18:16:03 -07001package claudetool
2
3import (
4 "context"
5 _ "embed"
6 "encoding/json"
7 "fmt"
8 "log/slog"
9 "strings"
10 "text/template"
11
12 "sketch.dev/llm"
13 "sketch.dev/llm/conversation"
14)
15
16// AboutSketch provides information about how to use Sketch.
17var AboutSketch = &llm.Tool{
18 Name: "about_sketch",
19 Description: aboutSketchDescription,
20 InputSchema: llm.EmptySchema(),
21 Run: aboutSketchRun,
22}
23
24// TODO: BYO knowledge bases? could do that for strings.Lines, for example.
25// TODO: support Q&A mode instead of reading full text in?
26
27const (
28 aboutSketchDescription = `Provides information about Sketch.
29
30When to use this tool:
31
32- The user is asking how to USE Sketch itself (not asking Sketch to perform a task)
33- The user has questions about Sketch functionality, setup, or capabilities
34- The user needs help with Sketch-specific concepts like running commands, secrets management, git integration
35- The query is about "How do I do X in Sketch?" or "Is it possible to Y in Sketch?" or just "Help"
36- The user is confused about how a Sketch feature works or how to access it
37- You need to know how to interact with the host environment, e.g. port forwarding or pulling changes the user has made outside of Sketch
38`
39)
40
41//go:embed about_sketch.txt
42var aboutSketch string
43
44var aboutSketchTemplate = template.Must(template.New("sketch").Parse(aboutSketch))
45
46func aboutSketchRun(ctx context.Context, m json.RawMessage) ([]llm.Content, error) {
47 slog.InfoContext(ctx, "about_sketch called")
48
49 info := conversation.ToolCallInfoFromContext(ctx)
50 sessionID, _ := info.Convo.ExtraData["session_id"].(string)
51 branch, _ := info.Convo.ExtraData["branch"].(string)
52 dot := struct {
53 SessionID string
54 Branch string
55 }{
56 SessionID: sessionID,
57 Branch: branch,
58 }
59 buf := new(strings.Builder)
60 if err := aboutSketchTemplate.Execute(buf, dot); err != nil {
61 return nil, fmt.Errorf("template execution error: %w", err)
62 }
63 return llm.TextContent(buf.String()), nil
64}