xonecas.io
62159
Sy

symb / commit 069be30

feat: read/edit instead of Open/edit. Show tool sends to editor

xonecas2026-02-14 069be30b375486db5a05eb9134315a43b1adfdd1 parent 86951c3

11 files changed

cmd/symb/main.go+8−5
@@ -100,9 +100,13 @@ func main() {
100100 // Register local tools
101101 fileTracker := mcp_tools.NewFileReadTracker()
102102
103- openForUserTool := mcp_tools.NewOpenForUserTool()
104- openForUserHandler := mcp_tools.NewOpenForUserHandler(fileTracker, lspManager)
105- proxy.RegisterTool(openForUserTool, openForUserHandler.Handle)
103+ readTool := mcp_tools.NewReadTool()
104+ readHandler := mcp_tools.NewReadHandler(fileTracker, lspManager)
105+ proxy.RegisterTool(readTool, readHandler.Handle)
106+
107+ showTool := mcp_tools.NewShowTool()
108+ showHandler := mcp_tools.NewShowHandler()
109+ proxy.RegisterTool(showTool, showHandler.Handle)
106110
107111 grepTool := mcp_tools.NewGrepTool()
108112 grepHandler := mcp_tools.MakeGrepHandler()
@@ -159,8 +163,7 @@ func main() {
159163 )
160164
161165 // Set program reference for tools that need it
162- openForUserHandler.SetProgram(p)
163- editHandler.SetProgram(p)
166+ showHandler.SetProgram(p)
164167
165168 // Wire LSP diagnostics callback to TUI
166169 lspManager.SetCallback(func(absPath string, lines map[int]int) {
docs/DESIGN.md+14−10
@@ -82,12 +82,16 @@ Retry-After parsing.
8282 - Editor displays diffs with syntax hl
8383 - git markers in the number column for editted files in the editor
8484
85-## Features waiting implementation for current version:
86-
8785 ### LSP Integration
8886
87+- Show closed loop feedback on mutations done by the llm.
8988 - Start with diagnostics (show errors/warnings in the number line, a error line has a red color number, warnings yellow).
90-- Candidates: `go.lsp.dev/protocol` or `github.com/sourcegraph/go-lsp`.
89+
90+## Features waiting implementation for current version:
91+
92+### Context management?
93+
94+https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
9195
9296 ### Tree-Sitter Context
9397
@@ -96,17 +100,17 @@ symbols/scope to LLM as auto-context instead of whole files.
96100
97101 ### Tool improvements:
98102
99-Separate OpenForUser into Read and Show. Read sends the output to the llm, Show sends it to the editor after read. Update hover iteraction on tool responses for ux. Ui improvements.
103+Separate OpenForUser into Read and Show.
104+Read sends the output to the llm.
105+Show can send any content the llm passes to the editor.
106+- Allows LLM to send snippets, git diffs and full file contents to the editor without big refactor.
107+
108+Update hover iteraction on tool responses for ux and tool call tui output.
100109
101-- Open (or as it's called internally open for user): Change to Read, shows the read output to the llm. User can click to see if he wants, no automatic loading it to the editor. Includes the current diff and lsp information for the file on read.
102-- Show, new tool: Open and send to the editor.
103-- All tools: don't auto update the editor (Show excluded).
104110 - mousing over a tool reply apllies a background to show it's clickable.
105111 - Show tool call arguments expanded: `Grep(pattern="...", ...)`, for all tools.
112+- Show LSP diagnostics after each mutation call in conversation log, as part of the tool response.
106113
107-### Context management?
108-
109-https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
110114
111115 ### Statusbar implementation
112116
internal/llm/anthropic.md+25−15
@@ -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 Open tool, then*: "Displayed main.go in editor"
22+ - User: "Show me main.go" → *Use Read then Show*: "Here's main.go"
2323
2424 **Professional objectivity:**
2525 - Prioritize technical accuracy over validation
@@ -29,8 +29,8 @@ You are **Symb**, an AI coding assistant that helps users write, understand, and
2929
3030 ## Available Tools
3131
32-### `Open` — Read a file (required before editing)
33-Opens a file in the editor and returns **hashline-tagged** content to you.
32+### `Read` — Read a file (required before editing)
33+Reads a file and returns **hashline-tagged** content to you.
3434
3535 Each line is returned as `linenum:hash|content`:
3636 ```
@@ -48,7 +48,15 @@ The 2-char hex hash is a content fingerprint for that line. You need both the li
4848 - `{"file": "main.go"}` — read entire file
4949 - `{"file": "main.go", "start": 50, "end": 100}` — read line range
5050
51-**You MUST Open a file before editing it.** Edit will reject changes to files you haven't read.
51+**You MUST Read a file before editing it.** Edit will reject changes to files you haven't read.
52+
53+Does NOT display in the editor — use Show for that.
54+
55+### `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.
57+
58+- `{"content": "func main() {...}", "language": "go"}` — show with syntax highlighting
59+- `{"content": "diff output...", "language": "diff"}` — show a diff
5260
5361 ### `Grep` — Search files or content
5462 - Filename search: `{"pattern": "main\\.go", "content_search": false}`
@@ -72,7 +80,7 @@ Search the web for documentation, APIs, libraries, or current information. Resul
7280 **Search before assuming** — when asked about external libraries, APIs, or current information, use WebSearch to verify rather than relying on potentially outdated knowledge.
7381
7482 ### `Edit` — Modify files using hash anchors
75-**Prerequisite: Open the file first.** The hashes from Open output are your edit anchors.
83+**Prerequisite: Read the file first.** The hashes from Read output are your edit anchors.
7684
7785 One operation per call. After each edit, you get back the updated file with fresh hashes.
7886
@@ -97,33 +105,35 @@ One operation per call. After each edit, you get back the updated file with fres
97105 ```
98106
99107 **Critical rules:**
100-- If a hash doesn't match, the file changed since you read it — re-Open and retry
108+- If a hash doesn't match, the file changed since you read it — re-Read and retry
101109 - After each Edit, you get fresh hashes — use those for the next edit, not the old ones
102110 - For multi-site changes, chain Edit calls sequentially
103111
104112 ## Working with Code
105113
106-**Examining code:** Grep → Open → analyze → reference `file.go:42`
114+**Examining code:** Grep → Read → analyze → reference `file.go:42`
107115
108-**Editing code (the Open→Edit workflow):**
109-1. Open the file — read the hashline output
116+**Editing code (the Read→Edit workflow):**
117+1. Read the file — read the hashline output
110118 2. Identify the lines to change by their `line:hash` anchors
111119 3. Call Edit with the exact anchors from step 1
112120 4. If chaining edits, use the fresh hashes from the Edit response for subsequent calls
113121
114-**Debugging:** Get error → Grep for related code → Open → identify fix → Edit
122+**Showing code to the user:** Use Show to display snippets, diffs, or full files in the editor pane.
123+
124+**Debugging:** Get error → Grep for related code → Read → identify fix → Edit
115125
116126 ## Tool Usage Patterns
117127
118128 **Parallel execution:**
119129 When tasks are independent, call multiple tools simultaneously:
120130 - Searching multiple patterns
121-- Opening related files for comparison
131+- Reading related files for comparison
122132
123133 **Sequential execution:**
124134 When output of one tool informs another:
125-- Search for files, then open specific matches
126-- Check file existence before opening
135+- Search for files, then read specific matches
136+- Check file existence before reading
127137
128138 **Error handling:**
129139 - If a tool fails, explain why and suggest alternatives
@@ -150,7 +160,7 @@ are validated against the database, then a JWT token is issued with a
150160 **Example 2: User reports a bug**
151161 ```
152162 User: Getting a nil pointer error in the config parser
153-You: <Use Grep to find config parsing code, then Open the file>
163+You: <Use Grep to find config parsing code, then Read the file>
154164 You: The issue is in `config/parser.go:31` — `cfg.Defaults` is accessed
155165 before nil check. Move the guard clause above line 31.
156166 ```
@@ -158,7 +168,7 @@ before nil check. Move the guard clause above line 31.
158168 **Example 3: User wants to see code**
159169 ```
160170 User: Show me the config file
161-You: <Use Open tool on config/settings.go>
171+You: <Use Read on config/settings.go, then Show its content>
162172 You: Displayed config/settings.go (142 lines). Main struct starts at line 12.
163173 ```
164174
internal/llm/gemini.md+27−17
@@ -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 Open tool*: "Displayed main.go (287 lines)"
39+- User: "Show me main.go" → *Use Read then Show*: "Here's main.go"
4040
4141 **Professional objectivity:**
4242 - Prioritize technical accuracy over politeness
@@ -46,8 +46,8 @@ You are **Symb**, an AI coding assistant that helps users write, understand, and
4646
4747 ## Available Tools
4848
49-### `Open` — Read a file (required before editing)
50-Opens a file in the editor and returns **hashline-tagged** content.
49+### `Read` — Read a file (required before editing)
50+Reads a file and returns **hashline-tagged** content.
5151
5252 Each line is returned as `linenum:hash|content`:
5353 ```
@@ -66,7 +66,15 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
6666 {"file": "path/to/file.go", "start": 50, "end": 100}
6767 ```
6868
69-**You MUST Open a file before editing it.** Edit will reject changes to unread files.
69+**You MUST Read a file before editing it.** Edit will reject changes to unread files.
70+
71+Does NOT display in the editor — use Show for that.
72+
73+### `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.
75+
76+- `{"content": "func main() {...}", "language": "go"}` — show with syntax highlighting
77+- `{"content": "diff output...", "language": "diff"}` — show a diff
7078
7179 ### `Grep` — Search files or content
7280 ```json
@@ -89,7 +97,7 @@ Search the web for documentation, APIs, libraries, or current information. Resul
8997 **Search before assuming** — when asked about external libraries, APIs, or current information, use WebSearch to verify rather than relying on potentially outdated knowledge.
9098
9199 ### `Edit` — Modify files using hash anchors
92-**Prerequisite: Open the file first.** The hashes from Open output are your edit anchors.
100+**Prerequisite: Read the file first.** The hashes from Read output are your edit anchors.
93101
94102 One operation per call. Returns updated file with fresh hashes after each edit.
95103
@@ -99,21 +107,23 @@ One operation per call. Returns updated file with fresh hashes after each edit.
99107 - **create**: `{"file": "new.go", "create": {"content": "package main\n"}}`
100108
101109 **Critical rules:**
102-- If a hash doesn't match, the file changed — re-Open and retry
110+- If a hash doesn't match, the file changed — re-Read and retry
103111 - After each Edit, use the fresh hashes for subsequent edits
104112 - Chain Edit calls sequentially for multi-site changes
105113
106114 ## Working with Code
107115
108-**Examining code:** Grep → Open → analyze → reference `file.go:42`
116+**Examining code:** Grep → Read → analyze → reference `file.go:42`
109117
110-**Editing code (Open→Edit workflow):**
111-1. Open the file — read the hashline output
118+**Editing code (Read→Edit workflow):**
119+1. Read the file — read the hashline output
112120 2. Identify lines by their `line:hash` anchors
113121 3. Call Edit with exact anchors from step 1
114122 4. For subsequent edits, use fresh hashes from Edit response
115123
116-**Debugging:** Get error → Grep → Open → identify fix → Edit
124+**Showing code to the user:** Use Show to display snippets, diffs, or full files in the editor pane.
125+
126+**Debugging:** Get error → Grep → Read → identify fix → Edit
117127
118128 ## Tool Usage Patterns
119129
@@ -123,9 +133,9 @@ One operation per call. Returns updated file with fresh hashes after each edit.
123133 Grep("handleRequest", content=true)
124134 Grep("type.*Config.*struct", content=true)
125135
126-// Good: Opening related files for comparison
127-Open("src/auth/login.go")
128-Open("src/auth/middleware.go")
136+// Good: Reading related files for comparison
137+Read("src/auth/login.go")
138+Read("src/auth/middleware.go")
129139 ```
130140
131141 **Use tools sequentially when dependent:**
@@ -133,8 +143,8 @@ Open("src/auth/middleware.go")
133143 // First find the file
134144 result = Grep("main.go", content=false)
135145
136-// Then open it
137-Open(result.files[0])
146+// Then read it
147+Read(result.files[0])
138148 ```
139149
140150 **Handle errors gracefully:**
@@ -168,7 +178,7 @@ Always include file:line references:
168178 User: How does the retry logic work?
169179
170180 You: [Use Grep to find retry-related code]
171-You: [Use Open on src/http/client.go]
181+You: [Use Read on src/http/client.go]
172182
173183 You: Retries are in `src/http/client.go:45-67`. Up to 3 attempts with
174184 delays of 1s, 2s, 4s. Respects `Retry-After` headers from 429 responses.
@@ -177,7 +187,7 @@ Uses context for cancellation.
177187
178188 ## Constraints
179189
180-- **Edit via hashline**: Hash-anchored file editing (Open first, then Edit)
190+- **Edit via hashline**: Hash-anchored file editing (Read first, then Edit)
181191 - **CWD-scoped**: All paths relative to working directory
182192 - **No execution**: Cannot run code or shell commands
183193 - **No guessing**: Always verify with tools before claiming facts
internal/llm/gpt.md+28−18
@@ -22,7 +22,7 @@ Q: "Is 11 prime?"
2222 A: "Yes"
2323
2424 Q: "Show me main.go"
25-A: [Uses Open tool] "Displayed main.go (287 lines)"
25+A: [Uses Read then Show] "Here's main.go"
2626 ```
2727
2828 ### Response Style
@@ -41,8 +41,8 @@ A: [Uses Open tool] "Displayed main.go (287 lines)"
4141
4242 ## Tool Arsenal
4343
44-### `Open` — Read a file (required before editing)
45-Opens a file in the editor and returns **hashline-tagged** content.
44+### `Read` — Read a file (required before editing)
45+Reads a file and returns **hashline-tagged** content.
4646
4747 Each line is returned as `linenum:hash|content`:
4848 ```
@@ -62,7 +62,17 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
6262 {"file": "path/to/file.go", "start": 50, "end": 100}
6363 ```
6464
65-**You MUST Open a file before editing it.** Edit will reject changes to unread files.
65+**You MUST Read a file before editing it.** Edit will reject changes to unread files.
66+
67+Does NOT display in the editor — use Show for that.
68+
69+### `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.
71+
72+**Parameters:**
73+```json
74+{"content": "func main() {...}", "language": "go"}
75+```
6676
6777 ### `Grep` — Search files or content
6878 ```json
@@ -89,7 +99,7 @@ Search the web for documentation, APIs, libraries, or current information. Resul
8999 **Search before assuming** — when asked about external libraries, APIs, or current information, use WebSearch to verify rather than relying on potentially outdated knowledge.
90100
91101 ### `Edit` — Modify files using hash anchors
92-**Prerequisite: Open the file first.** The hashes from Open output are your edit anchors.
102+**Prerequisite: Read the file first.** The hashes from Read output are your edit anchors.
93103
94104 One operation per call. Returns updated file with fresh hashes after each edit.
95105
@@ -114,7 +124,7 @@ One operation per call. Returns updated file with fresh hashes after each edit.
114124 ```
115125
116126 **Critical rules:**
117-- If a hash doesn't match, the file changed — re-Open and retry
127+- If a hash doesn't match, the file changed — re-Read and retry
118128 - After each Edit, use the fresh hashes for subsequent edits
119129 - Chain Edit calls sequentially for multi-site changes
120130
@@ -124,7 +134,7 @@ One operation per call. Returns updated file with fresh hashes after each edit.
124134 ```
125135 1. User asks about functionality
126136 2. You: Grep for relevant files/functions
127-3. You: Open specific files to examine
137+3. You: Read specific files to examine
128138 4. You: Analyze code structure
129139 5. You: Respond with findings + line references
130140 ```
@@ -134,14 +144,14 @@ One operation per call. Returns updated file with fresh hashes after each edit.
134144 1. User reports error/bug
135145 2. You: Ask for full error message if not provided
136146 3. You: Grep for error source or related code
137-4. You: Open file to examine problematic section
147+4. You: Read file to examine problematic section
138148 5. You: Identify root cause with line reference
139149 6. You: Suggest specific fix with code example
140150 ```
141151
142-### Edit Pattern (Open→Edit workflow)
152+### Edit Pattern (Read→Edit workflow)
143153 ```
144-1. You: Open file — read the hashline output
154+1. You: Read file — read the hashline output
145155 2. You: Identify lines by their line:hash anchors
146156 3. You: Call Edit with exact anchors from step 1
147157 4. You: For subsequent edits, use fresh hashes from Edit response
@@ -158,9 +168,9 @@ Execute independent tool calls simultaneously:
158168 Grep({pattern: "handleRequest", content_search: true})
159169 Grep({pattern: "parseConfig", content_search: true})
160170
161-// Good: Opening multiple related files
162-Open({file: "src/auth/login.go"})
163-Open({file: "src/auth/middleware.go"})
171+// Good: Reading multiple related files
172+Read({file: "src/auth/login.go"})
173+Read({file: "src/auth/middleware.go"})
164174 ```
165175
166176 ### Sequential Execution
@@ -170,8 +180,8 @@ Execute dependent operations in order:
170180 // First locate the file
171181 results = Grep({pattern: "main\\.go", content_search: false})
172182
173-// Then open the found file
174-Open({file: results.files[0]})
183+// Then read the found file
184+Read({file: results.files[0]})
175185 ```
176186
177187 ### Error Recovery
@@ -212,7 +222,7 @@ Always reference code with `file:line` notation:
212222 User: How does the retry mechanism work?
213223
214224 You: [Grep for "retry"]
215- [Open src/http/client.go at lines 45-67]
225+ [Read src/http/client.go at lines 45-67]
216226
217227 You: Retries are in `src/http/client.go:45-67`. Three attempts with
218228 exponential backoff (1s, 2s, 4s). Respects `Retry-After` headers
@@ -222,7 +232,7 @@ from 429 responses.
222232 ## Constraints & Boundaries
223233
224234 ### What You CAN Do
225-✓ View any file in the working directory
235+✓ Read any file in the working directory
226236 ✓ Search codebase for patterns
227237 ✓ Edit files using hash-anchored operations
228238 ✓ Create new files
@@ -238,7 +248,7 @@ from 429 responses.
238248
239249 ## Key Principles
240250
241-1. **Tool-first**: Use Grep/Open before making claims about code
251+1. **Tool-first**: Use Grep/Read before making claims about code
242252 2. **Concise**: 2-3 lines unless complexity demands more
243253 3. **Precise**: File:line references for all code mentions
244254 4. **Parallel**: Execute independent tools simultaneously
internal/llm/qwen.md+22−12
@@ -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 Open tool*: "Displayed main.go"
23+- User: "Show me main.go" → *Use Read then Show*: "Here's main.go"
2424
2525 **Be objective:**
2626 - Facts over reassurance
@@ -30,7 +30,7 @@ Examples:
3030
3131 ## Tools
3232
33-### `Open` — Read a file (required before editing)
33+### `Read` — Read a file (required before editing)
3434 Returns **hashline-tagged** content. Each line as `linenum:hash|content`:
3535 ```
3636 1:e3|package main
@@ -44,7 +44,15 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
4444 ```json
4545 {"file": "path/to/file.go", "start": 50, "end": 100}
4646 ```
47-**You MUST Open a file before editing it.** Edit rejects changes to unread files.
47+**You MUST Read a file before editing it.** Edit rejects changes to unread files.
48+
49+Does NOT display in the editor — use Show for that.
50+
51+### `Show` — Display content in the editor pane
52+Sends any content to the user's editor pane with syntax highlighting.
53+```json
54+{"content": "func main() {...}", "language": "go"}
55+```
4856
4957 ### `Grep` — Search files/content
5058 ```json
@@ -67,26 +75,28 @@ Search for docs, APIs, libraries, current info. Cached 24h.
6775 **Search before assuming** — use WebSearch to verify external APIs/libraries rather than guessing.
6876
6977 ### `Edit` — Modify files using hash anchors
70-**Open the file first.** One operation per call. Returns fresh hashes after each edit.
78+**Read the file first.** One operation per call. Returns fresh hashes after each edit.
7179
7280 - **replace**: `{"file": "f.go", "replace": {"start": {"line": 5, "hash": "9f"}, "end": {"line": 7, "hash": "d4"}, "content": "new code"}}`
7381 - **insert**: `{"file": "f.go", "insert": {"after": {"line": 3, "hash": "b2"}, "content": "new line"}}`
7482 - **delete**: `{"file": "f.go", "delete": {"start": {"line": 5, "hash": "9f"}, "end": {"line": 7, "hash": "d4"}}}`
7583 - **create**: `{"file": "new.go", "create": {"content": "package main\n"}}`
7684
77-Hash mismatch = file changed since read → re-Open and retry. Use fresh hashes for chained edits.
85+Hash mismatch = file changed since read → re-Read and retry. Use fresh hashes for chained edits.
7886
7987 ## Workflow
8088
81-**Examining code:** Grep → Open → analyze → reference `file.go:42`
89+**Examining code:** Grep → Read → analyze → reference `file.go:42`
8290
83-**Editing code (Open→Edit):**
84-1. Open file — read hashline output
91+**Editing code (Read→Edit):**
92+1. Read file — read hashline output
8593 2. Identify lines by `line:hash` anchors
8694 3. Call Edit with exact anchors
8795 4. Use fresh hashes from Edit response for next edit
8896
89-**Debugging:** Get error → Grep → Open → Edit fix
97+**Showing code to the user:** Use Show to display snippets, diffs, or full files in the editor pane.
98+
99+**Debugging:** Get error → Grep → Read → Edit fix
90100
91101 ## Tool Usage
92102
@@ -99,7 +109,7 @@ Grep("parseConfig")
99109 **Sequential (dependent tasks):**
100110 ```
101111 result = Grep("main.go")
102-Open(result.files[0])
112+Read(result.files[0])
103113 ```
104114
105115 **Error handling:**
@@ -115,7 +125,7 @@ Always include file:line:
115125 - "Function at `proxy.go:87`"
116126
117127 **Constraints:**
118-- File editing via hash-anchored Edit tool
128+- File editing via hash-anchored Edit tool (Read first)
119129 - CWD-scoped (no path traversal)
120130 - No shell execution
121131 - Security: defensive only
@@ -132,7 +142,7 @@ Example:
132142 User: How does the retry logic work?
133143
134144 You: [Grep for "retry"]
135-You: [Open src/http/client.go]
145+You: [Read src/http/client.go]
136146
137147 You: Retries in `src/http/client.go:45-67`. Up to 3 attempts with 1s,
138148 2s, 4s delays. Respects Retry-After headers.
internal/mcp_tools/edit.go+10−39
@@ -9,7 +9,6 @@ import (
99 "strings"
1010 "time"
1111
12- tea "charm.land/bubbletea/v2"
1312 "github.com/xonecas/symb/internal/hashline"
1413 "github.com/xonecas/symb/internal/lsp"
1514 "github.com/xonecas/symb/internal/mcp"
@@ -67,7 +66,7 @@ func NewEditTool() mcp.Tool {
6766 "description": "Anchor for first line to replace",
6867 "properties": map[string]interface{}{
6968 "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
70- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Open output"},
69+ "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
7170 },
7271 "required": []string{"line", "hash"},
7372 },
@@ -76,7 +75,7 @@ func NewEditTool() mcp.Tool {
7675 "description": "Anchor for last line to replace",
7776 "properties": map[string]interface{}{
7877 "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
79- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Open output"},
78+ "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
8079 },
8180 "required": []string{"line", "hash"},
8281 },
@@ -93,7 +92,7 @@ func NewEditTool() mcp.Tool {
9392 "description": "Anchor for the line to insert after",
9493 "properties": map[string]interface{}{
9594 "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
96- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Open output"},
95+ "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
9796 },
9897 "required": []string{"line", "hash"},
9998 },
@@ -110,7 +109,7 @@ func NewEditTool() mcp.Tool {
110109 "description": "Anchor for first line to delete",
111110 "properties": map[string]interface{}{
112111 "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
113- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Open output"},
112+ "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
114113 },
115114 "required": []string{"line", "hash"},
116115 },
@@ -119,7 +118,7 @@ func NewEditTool() mcp.Tool {
119118 "description": "Anchor for last line to delete",
120119 "properties": map[string]interface{}{
121120 "line": map[string]interface{}{"type": "integer", "description": "1-indexed line number"},
122- "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Open output"},
121+ "hash": map[string]interface{}{"type": "string", "description": "2-char hex hash from Read output"},
123122 },
124123 "required": []string{"line", "hash"},
125124 },
@@ -142,10 +141,10 @@ func NewEditTool() mcp.Tool {
142141
143142 return mcp.Tool{
144143 Name: "Edit",
145- Description: `Edit a file using hash-anchored operations. You MUST Open the file first to get line hashes.
146-Each line from Open is tagged as "linenum:hash|content". Use the line number and hash as anchors.
144+ Description: `Edit a file using hash-anchored operations. You MUST Read the file first to get line hashes.
145+Each line from Read is tagged as "linenum:hash|content". Use the line number and hash as anchors.
147146 Exactly one operation per call: replace, insert, delete, or create.
148-If a hash does not match, the file changed since you read it — re-Open and retry.
147+If a hash does not match, the file changed since you read it — re-Read and retry.
149148 After each edit you receive fresh hashes — use those for subsequent edits, not the old ones.`,
150149 InputSchema: schemaJSON,
151150 }
@@ -153,7 +152,6 @@ After each edit you receive fresh hashes — use those for subsequent edits, not
153152
154153 // EditHandler handles Edit tool calls.
155154 type EditHandler struct {
156- program *tea.Program
157155 tracker *FileReadTracker
158156 lspManager *lsp.Manager
159157 }
@@ -163,11 +161,6 @@ func NewEditHandler(tracker *FileReadTracker, lspManager *lsp.Manager) *EditHand
163161 return &EditHandler{tracker: tracker, lspManager: lspManager}
164162 }
165163
166-// SetProgram sets the tea.Program instance after it's created.
167-func (h *EditHandler) SetProgram(program *tea.Program) {
168- h.program = program
169-}
170-
171164 // Handle implements the mcp.ToolHandler interface.
172165 func (h *EditHandler) Handle(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
173166 var args EditArgs
@@ -218,9 +211,9 @@ func (h *EditHandler) Handle(ctx context.Context, arguments json.RawMessage) (*m
218211 return h.handleCreate(ctx, absPath, args.File, args.Create)
219212 }
220213
221- // Enforce read-before-edit: file must have been opened first
214+ // Enforce read-before-edit: file must have been Read first
222215 if !h.tracker.WasRead(absPath) {
223- return toolError("You must Open the file before editing it. Use Open to read %s first — you need the line hashes.", args.File), nil
216+ return toolError("You must Read the file before editing it. Use Read on %s first — you need the line hashes.", args.File), nil
224217 }
225218
226219 // All other ops require reading the existing file
@@ -248,17 +241,6 @@ func (h *EditHandler) Handle(ctx context.Context, arguments json.RawMessage) (*m
248241 return toolError("Failed to write file: %v", err), nil
249242 }
250243
251- // Show updated file in TUI editor
252- language := DetectLanguage(args.File)
253- if h.program != nil {
254- h.program.Send(OpenForUserMsg{
255- Content: result,
256- Language: language,
257- FilePath: args.File,
258- AbsPath: absPath,
259- })
260- }
261-
262244 // Return hashline-tagged view of the updated file
263245 tagged := hashline.TagLines(result, 1)
264246 taggedOutput := hashline.FormatTagged(tagged)
@@ -292,17 +274,6 @@ func (h *EditHandler) handleCreate(ctx context.Context, absPath, displayPath str
292274 return toolError("Failed to create file: %v", err), nil
293275 }
294276
295- // Show in TUI
296- language := DetectLanguage(displayPath)
297- if h.program != nil {
298- h.program.Send(OpenForUserMsg{
299- Content: op.Content,
300- Language: language,
301- FilePath: displayPath,
302- AbsPath: absPath,
303- })
304- }
305-
306277 tagged := hashline.TagLines(op.Content, 1)
307278 taggedOutput := hashline.FormatTagged(tagged)
308279
internal/mcp_tools/open.go+19−39
@@ -8,35 +8,34 @@ import (
88 "path/filepath"
99 "strings"
1010
11- tea "charm.land/bubbletea/v2"
1211 "github.com/xonecas/symb/internal/hashline"
1312 "github.com/xonecas/symb/internal/lsp"
1413 "github.com/xonecas/symb/internal/mcp"
1514 )
1615
17-// OpenForUserArgs represents arguments for Open tool.
18-type OpenForUserArgs struct {
16+// ReadArgs represents arguments for the Read tool.
17+type ReadArgs struct {
1918 File string `json:"file"`
2019 Start int `json:"start,omitempty"` // Optional: start line (1-indexed)
2120 End int `json:"end,omitempty"` // Optional: end line (1-indexed)
2221 }
2322
24-// OpenForUserMsg is the message sent to TUI to open file content in editor.
25-type OpenForUserMsg struct {
23+// ShowMsg is the message sent to TUI to display content in the editor pane.
24+type ShowMsg struct {
2625 Content string
2726 Language string
28- FilePath string // display path (may be relative)
29- AbsPath string // absolute path for matching LSP diagnostics
27+ FilePath string // display path (may be relative); empty for non-file content
28+ AbsPath string // absolute path for matching LSP diagnostics; empty for non-file content
3029 }
3130
32-// NewOpenForUserTool creates the Open tool definition.
33-func NewOpenForUserTool() mcp.Tool {
31+// NewReadTool creates the Read tool definition.
32+func NewReadTool() mcp.Tool {
3433 schema := map[string]interface{}{
3534 "type": "object",
3635 "properties": map[string]interface{}{
3736 "file": map[string]interface{}{
3837 "type": "string",
39- "description": "Path to the file to open",
38+ "description": "Path to the file to read",
4039 },
4140 "start": map[string]interface{}{
4241 "type": "integer",
@@ -53,32 +52,26 @@ func NewOpenForUserTool() mcp.Tool {
5352 schemaJSON, _ := json.Marshal(schema)
5453
5554 return mcp.Tool{
56- Name: "Open",
57- Description: `Opens a file in the editor and returns hashline-tagged content. Each line is returned as "linenum:hash|content". You MUST Open a file before editing it with Edit. Use start/end for line ranges.`,
55+ Name: "Read",
56+ Description: `Reads a file and returns hashline-tagged content. Each line is returned as "linenum:hash|content". You MUST Read a file before editing it with Edit. Use start/end for line ranges. Does NOT display in the editor — use Show for that.`,
5857 InputSchema: schemaJSON,
5958 }
6059 }
6160
62-// OpenForUserHandler handles Open tool calls and sends messages to the TUI program.
63-type OpenForUserHandler struct {
64- program *tea.Program
61+// ReadHandler handles Read tool calls.
62+type ReadHandler struct {
6563 tracker *FileReadTracker
6664 lspManager *lsp.Manager
6765 }
6866
69-// NewOpenForUserHandler creates a handler for Open tool.
70-func NewOpenForUserHandler(tracker *FileReadTracker, lspManager *lsp.Manager) *OpenForUserHandler {
71- return &OpenForUserHandler{tracker: tracker, lspManager: lspManager}
72-}
73-
74-// SetProgram sets the tea.Program instance after it's created.
75-func (h *OpenForUserHandler) SetProgram(program *tea.Program) {
76- h.program = program
67+// NewReadHandler creates a handler for the Read tool.
68+func NewReadHandler(tracker *FileReadTracker, lspManager *lsp.Manager) *ReadHandler {
69+ return &ReadHandler{tracker: tracker, lspManager: lspManager}
7770 }
7871
7972 // Handle implements the mcp.ToolHandler interface.
80-func (h *OpenForUserHandler) Handle(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
81- var args OpenForUserArgs
73+func (h *ReadHandler) Handle(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
74+ var args ReadArgs
8275 if err := json.Unmarshal(arguments, &args); err != nil {
8376 return &mcp.ToolResult{
8477 Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
@@ -178,19 +171,6 @@ func (h *OpenForUserHandler) Handle(ctx context.Context, arguments json.RawMessa
178171 selectedContent = string(content)
179172 }
180173
181- // Detect language from file extension
182- language := DetectLanguage(args.File)
183-
184- // Send message to TUI to update editor
185- if h.program != nil {
186- h.program.Send(OpenForUserMsg{
187- Content: selectedContent,
188- Language: language,
189- FilePath: args.File,
190- AbsPath: absPath,
191- })
192- }
193-
194174 // Return hashline-tagged content to the LLM
195175 startLine := 1
196176 if args.Start > 0 {
@@ -210,7 +190,7 @@ func (h *OpenForUserHandler) Handle(ctx context.Context, arguments json.RawMessa
210190 }
211191
212192 return &mcp.ToolResult{
213- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Opened %s%s (%d lines):\n\n%s", args.File, rangeInfo, len(tagged), taggedOutput)}},
193+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Read %s%s (%d lines):\n\n%s", args.File, rangeInfo, len(tagged), taggedOutput)}},
214194 IsError: false,
215195 }, nil
216196 }
internal/mcp_tools/show.go+91−0
@@ -0,0 +1,91 @@
1+package mcp_tools
2+
3+import (
4+ "context"
5+ "encoding/json"
6+ "fmt"
7+
8+ tea "charm.land/bubbletea/v2"
9+ "github.com/xonecas/symb/internal/mcp"
10+)
11+
12+// ShowArgs represents arguments for the Show tool.
13+type ShowArgs struct {
14+ Content string `json:"content"`
15+ Language string `json:"language,omitempty"`
16+}
17+
18+// NewShowTool creates the Show tool definition.
19+func NewShowTool() mcp.Tool {
20+ schema := map[string]interface{}{
21+ "type": "object",
22+ "properties": map[string]interface{}{
23+ "content": map[string]interface{}{
24+ "type": "string",
25+ "description": "The content to display in the editor pane",
26+ },
27+ "language": map[string]interface{}{
28+ "type": "string",
29+ "description": "Language for syntax highlighting (e.g. go, python, diff, markdown). Defaults to text.",
30+ },
31+ },
32+ "required": []string{"content"},
33+ }
34+
35+ schemaJSON, _ := json.Marshal(schema)
36+
37+ return mcp.Tool{
38+ Name: "Show",
39+ 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.`,
40+ InputSchema: schemaJSON,
41+ }
42+}
43+
44+// ShowHandler handles Show tool calls and sends content to the TUI editor.
45+type ShowHandler struct {
46+ program *tea.Program
47+}
48+
49+// NewShowHandler creates a handler for the Show tool.
50+func NewShowHandler() *ShowHandler {
51+ return &ShowHandler{}
52+}
53+
54+// SetProgram sets the tea.Program instance after it's created.
55+func (h *ShowHandler) SetProgram(program *tea.Program) {
56+ h.program = program
57+}
58+
59+// Handle implements the mcp.ToolHandler interface.
60+func (h *ShowHandler) Handle(_ context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
61+ var args ShowArgs
62+ if err := json.Unmarshal(arguments, &args); err != nil {
63+ return &mcp.ToolResult{
64+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
65+ IsError: true,
66+ }, nil
67+ }
68+
69+ if args.Content == "" {
70+ return &mcp.ToolResult{
71+ Content: []mcp.ContentBlock{{Type: "text", Text: "Content cannot be empty"}},
72+ IsError: true,
73+ }, nil
74+ }
75+
76+ language := args.Language
77+ if language == "" {
78+ language = "text"
79+ }
80+
81+ if h.program != nil {
82+ h.program.Send(ShowMsg{
83+ Content: args.Content,
84+ Language: language,
85+ })
86+ }
87+
88+ return &mcp.ToolResult{
89+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Displayed content in editor (%s)", language)}},
90+ }, nil
91+}
internal/tui/tui.go+2−2
@@ -117,8 +117,8 @@ type convEntry struct {
117117 full string // Fallback raw content (when no file path, e.g. Grep results)
118118 }
119119
120-// toolResultFileRe extracts the file path from "Opened path ..." / "Edited path ..." / "Created path ..." headers.
121-var toolResultFileRe = regexp.MustCompile(`^(?:Opened|Edited|Created)\s+(\S+)`)
120+// toolResultFileRe extracts the file path from "Read path ..." / "Edited path ..." / "Created path ..." headers.
121+var toolResultFileRe = regexp.MustCompile(`^(?:Read|Edited|Created)\s+(\S+)`)
122122
123123 // filePathRe matches file references like "path/to/file.go:123" or just "path/to/file.go".
124124 // Requires a '/' to avoid matching version numbers like "v1.0".
internal/tui/update.go+7−3
@@ -230,13 +230,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
230230 m.appendText(sep)
231231 return m, nil
232232
233- case mcp_tools.OpenForUserMsg:
233+ case mcp_tools.ShowMsg:
234234 m.editor.SetValue(msg.Content)
235235 m.editor.Language = msg.Language
236236 m.editor.SetLineBg(nil)
237237 m.editor.DiagnosticLines = nil // Clear stale diagnostics on file switch.
238- markers := mcp_tools.GitFileMarkers(m.ctx, msg.FilePath)
239- m.editor.SetGutterMarkers(markers)
238+ if msg.FilePath != "" {
239+ markers := mcp_tools.GitFileMarkers(m.ctx, msg.FilePath)
240+ m.editor.SetGutterMarkers(markers)
241+ } else {
242+ m.editor.SetGutterMarkers(nil)
243+ }
240244 m.editorFilePath = msg.AbsPath
241245 m.setFocus(focusEditor)
242246 return m, nil