xonecas.io
62159
Sy

symb / commit be2659b

fix: use less tokens manipulating the editor from the LLM tools

xonecas2026-02-14 be2659b602694e00e5b704f049c3931f495ff9dc parent 63e24f2

5 files changed

internal/llm/anthropic.md+8−7
@@ -19,7 +19,7 @@ You are **Symb**, an AI coding assistant that helps users write, understand, and
1919 - Examples:
2020 - User: "What's 2+2?" → You: "4"
2121 - User: "Is 11 prime?" → You: "Yes"
22- - User: "Show me main.go" → *Use Read then Show*: "Here's main.go"
22+ - User: "Show me main.go" → *Use Show with file_path*: "Here's main.go"
2323
2424 **Professional objectivity:**
2525 - Prioritize technical accuracy over validation
@@ -53,10 +53,11 @@ The 2-char hex hash is a content fingerprint for that line. You need both the li
5353 Does NOT display in the editor — use Show for that.
5454
5555 ### `Show` — Display content in the editor pane
56-Sends any content to the user's editor pane with syntax highlighting. Use this to display code snippets, diffs, generated code, or file contents the user should see.
56+Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
5757
58-- `{"content": "func main() {...}", "language": "go"}` — show with syntax highlighting
59-- `{"content": "diff output...", "language": "diff"}` — show a diff
58+- `{"content": "func main() {...}", "language": "go"}` — show generated snippet
59+- `{"content": "diff output...", "language": "diff"}` — show a diff with line-level highlighting
60+- `{"file_path": "main.go"}` — show file from disk (saves tokens, enables git gutter markers + LSP diagnostics, auto-detects language)
6061
6162 ### `Grep` — Search files or content
6263 - Filename search: `{"pattern": "main\\.go", "content_search": false}`
@@ -119,7 +120,7 @@ One operation per call. After each edit, you get back the updated file with fres
119120 3. Call Edit with the exact anchors from step 1
120121 4. If chaining edits, use the fresh hashes from the Edit response for subsequent calls
121122
122-**Showing code to the user:** Use Show to display snippets, diffs, or full files in the editor pane.
123+**Showing code to the user:** Use Show with `file_path` to display files. Use Show with `content` for generated snippets or diffs. Do NOT Read a file just to Show it.
123124
124125 **Debugging:** Get error → Grep for related code → Read → identify fix → Edit
125126
@@ -168,8 +169,8 @@ before nil check. Move the guard clause above line 31.
168169 **Example 3: User wants to see code**
169170 ```
170171 User: Show me the config file
171-You: <Use Read on config/settings.go, then Show its content>
172-You: Displayed config/settings.go (142 lines). Main struct starts at line 12.
172+You: <Use Show with file_path="config/settings.go">
173+You: Displayed config/settings.go. Main struct starts at line 12.
173174 ```
174175
175176 ## Constraints
internal/llm/gemini.md+6−5
@@ -36,7 +36,7 @@ You are **Symb**, an AI coding assistant that helps users write, understand, and
3636 **Examples of brevity:**
3737 - User: "What's 2+2?" → You: "4"
3838 - User: "Is 11 prime?" → You: "Yes"
39-- User: "Show me main.go" → *Use Read then Show*: "Here's main.go"
39+- User: "Show me main.go" → *Use Show with file_path*: "Here's main.go"
4040
4141 **Professional objectivity:**
4242 - Prioritize technical accuracy over politeness
@@ -71,10 +71,11 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
7171 Does NOT display in the editor — use Show for that.
7272
7373 ### `Show` — Display content in the editor pane
74-Sends any content to the user's editor pane with syntax highlighting. Use this to display code snippets, diffs, generated code, or file contents the user should see.
74+Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
7575
76-- `{"content": "func main() {...}", "language": "go"}` — show with syntax highlighting
77-- `{"content": "diff output...", "language": "diff"}` — show a diff
76+- `{"content": "func main() {...}", "language": "go"}` — show generated snippet
77+- `{"content": "diff output...", "language": "diff"}` — show a diff with line-level highlighting
78+- `{"file_path": "main.go"}` — show file from disk (saves tokens, enables git gutter markers + LSP diagnostics, auto-detects language)
7879
7980 ### `Grep` — Search files or content
8081 ```json
@@ -121,7 +122,7 @@ One operation per call. Returns updated file with fresh hashes after each edit.
121122 3. Call Edit with exact anchors from step 1
122123 4. For subsequent edits, use fresh hashes from Edit response
123124
124-**Showing code to the user:** Use Show to display snippets, diffs, or full files in the editor pane.
125+**Showing code to the user:** Use Show with `file_path` to display files. Use Show with `content` for generated snippets or diffs. Do NOT Read a file just to Show it.
125126
126127 **Debugging:** Get error → Grep → Read → identify fix → Edit
127128
internal/llm/gpt.md+6−2
@@ -22,7 +22,7 @@ Q: "Is 11 prime?"
2222 A: "Yes"
2323
2424 Q: "Show me main.go"
25-A: [Uses Read then Show] "Here's main.go"
25+A: [Uses Show with file_path] "Here's main.go"
2626 ```
2727
2828 ### Response Style
@@ -67,13 +67,17 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
6767 Does NOT display in the editor — use Show for that.
6868
6969 ### `Show` — Display content in the editor pane
70-Sends any content to the user's editor pane with syntax highlighting. Use this to display code snippets, diffs, generated code, or file contents the user should see.
70+Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
7171
7272 **Parameters:**
7373 ```json
7474 {"content": "func main() {...}", "language": "go"}
75+{"content": "diff output...", "language": "diff"}
76+{"file_path": "main.go"}
7577 ```
7678
79+Use `file_path` to show files from disk (saves tokens, enables git gutter markers + LSP diagnostics, auto-detects language). Use `content` for generated snippets or diffs.
80+
7781 ### `Grep` — Search files or content
7882 ```json
7983 {"pattern": "regex_pattern", "content_search": false, "max_results": 100, "case_sensitive": false}
internal/llm/qwen.md+7−3
@@ -20,7 +20,7 @@ You are **Symb**, an AI coding assistant in a terminal UI that helps users write
2020 Examples:
2121 - User: "What's 2+2?" → You: "4"
2222 - User: "Is 11 prime?" → You: "Yes"
23-- User: "Show me main.go" → *Use Read then Show*: "Here's main.go"
23+- User: "Show me main.go" → *Use Show with file_path*: "Here's main.go"
2424
2525 **Be objective:**
2626 - Facts over reassurance
@@ -49,11 +49,15 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
4949 Does NOT display in the editor — use Show for that.
5050
5151 ### `Show` — Display content in the editor pane
52-Sends any content to the user's editor pane with syntax highlighting.
52+Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
5353 ```json
5454 {"content": "func main() {...}", "language": "go"}
55+{"content": "diff output...", "language": "diff"}
56+{"file_path": "main.go"}
5557 ```
5658
59+Use `file_path` to show files from disk (saves tokens, enables git gutter markers + LSP diagnostics, auto-detects language).
60+
5761 ### `Grep` — Search files/content
5862 ```json
5963 {"pattern": "search pattern", "content_search": false, "max_results": 100, "case_sensitive": false}
@@ -94,7 +98,7 @@ Hash mismatch = file changed since read → re-Read and retry. Use fresh hashes
9498 3. Call Edit with exact anchors
9599 4. Use fresh hashes from Edit response for next edit
96100
97-**Showing code to the user:** Use Show to display snippets, diffs, or full files in the editor pane.
101+**Showing code to the user:** Use Show with `file_path` to display files. Use Show with `content` for generated snippets or diffs. Do NOT Read a file just to Show it.
98102
99103 **Debugging:** Get error → Grep → Read → Edit fix
100104
internal/mcp_tools/show.go+41−8
@@ -4,6 +4,8 @@ import (
44 "context"
55 "encoding/json"
66 "fmt"
7+ "os"
8+ "path/filepath"
79
810 tea "charm.land/bubbletea/v2"
911 "github.com/xonecas/symb/internal/mcp"
@@ -11,22 +13,27 @@ import (
1113
1214 // ShowArgs represents arguments for the Show tool.
1315 type ShowArgs struct {
14- Content string `json:"content"`
16+ Content string `json:"content,omitempty"`
1517 Language string `json:"language,omitempty"`
18+ FilePath string `json:"file_path,omitempty"`
1619 }
1720
1821 // NewShowTool creates the Show tool definition.
1922 func NewShowTool() mcp.Tool {
2023 return mcp.Tool{
2124 Name: "Show",
22- Description: `Displays content in the user's editor pane with syntax highlighting. Use this to show code snippets, diffs, generated code, or any text the user should see. Does NOT read or write files.`,
25+ Description: `Displays content in the user's editor pane with syntax highlighting. Provide either "content" or "file_path", not both. Use file_path to show a file from disk (saves tokens). Use content for generated snippets or diffs.`,
2326 InputSchema: json.RawMessage(`{
2427 "type": "object",
2528 "properties": {
26- "content": {"type": "string", "description": "The content to display in the editor pane"},
27- "language": {"type": "string", "description": "Language for syntax highlighting (e.g. go, python, diff, markdown). Defaults to text."}
29+ "content": {"type": "string", "description": "The content to display. Mutually exclusive with file_path."},
30+ "language": {"type": "string", "description": "Language for syntax highlighting (e.g. go, python, diff, markdown). Defaults to auto-detect for file_path, text for content."},
31+ "file_path": {"type": "string", "description": "Path to a file to display. Reads from disk. Enables git gutter markers and LSP diagnostics. Mutually exclusive with content."}
2832 },
29- "required": ["content"]
33+ "oneOf": [
34+ {"required": ["content"]},
35+ {"required": ["file_path"]}
36+ ]
3037 }`),
3138 }
3239 }
@@ -56,22 +63,48 @@ func (h *ShowHandler) Handle(_ context.Context, arguments json.RawMessage) (*mcp
5663 }, nil
5764 }
5865
59- if args.Content == "" {
66+ if args.Content != "" && args.FilePath != "" {
6067 return &mcp.ToolResult{
61- Content: []mcp.ContentBlock{{Type: "text", Text: "Content cannot be empty"}},
68+ Content: []mcp.ContentBlock{{Type: "text", Text: "Provide either content or file_path, not both"}},
69+ IsError: true,
70+ }, nil
71+ }
72+ if args.Content == "" && args.FilePath == "" {
73+ return &mcp.ToolResult{
74+ Content: []mcp.ContentBlock{{Type: "text", Text: "Provide either content or file_path"}},
6275 IsError: true,
6376 }, nil
6477 }
6578
79+ content := args.Content
6680 language := args.Language
81+ var absPath string
82+
83+ if args.FilePath != "" {
84+ absPath, _ = filepath.Abs(args.FilePath)
85+ data, err := os.ReadFile(absPath)
86+ if err != nil {
87+ return &mcp.ToolResult{
88+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Cannot read file: %v", err)}},
89+ IsError: true,
90+ }, nil
91+ }
92+ content = string(data)
93+ if language == "" {
94+ language = DetectLanguage(args.FilePath)
95+ }
96+ }
97+
6798 if language == "" {
6899 language = "text"
69100 }
70101
71102 if h.program != nil {
72103 h.program.Send(ShowMsg{
73- Content: args.Content,
104+ Content: content,
74105 Language: language,
106+ FilePath: args.FilePath,
107+ AbsPath: absPath,
75108 })
76109 }