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