| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 1 | package claudetool |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | _ "embed" |
| 6 | "encoding/json" |
| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 7 | "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. |
| 16 | var 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 | |
| 26 | const ( |
| 27 | aboutSketchDescription = `Provides information about Sketch. |
| 28 | |
| 29 | When 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 |
| 41 | var aboutSketch string |
| 42 | |
| 43 | var aboutSketchTemplate = template.Must(template.New("sketch").Parse(aboutSketch)) |
| 44 | |
| Josh Bleecher Snyder | 43b60b9 | 2025-07-21 14:57:10 -0700 | [diff] [blame] | 45 | func aboutSketchRun(ctx context.Context, m json.RawMessage) llm.ToolOut { |
| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 46 | 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 Snyder | 43b60b9 | 2025-07-21 14:57:10 -0700 | [diff] [blame] | 60 | return llm.ErrorfToolOut("template execution error: %w", err) |
| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 61 | } |
| Josh Bleecher Snyder | 43b60b9 | 2025-07-21 14:57:10 -0700 | [diff] [blame] | 62 | return llm.ToolOut{LLMContent: llm.TextContent(buf.String())} |
| Josh Bleecher Snyder | 74d690e | 2025-05-14 18:16:03 -0700 | [diff] [blame] | 63 | } |