xonecas.io
62159
Sy

symb / commit a97ccdd

fix: remove features I tested with and didnt like at all

xonecas2026-02-14 a97ccdd395960f800ee6911697be66f954798804 parent 2492a25

18 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

cmd/symb/main.go+3−9
@@ -47,7 +47,7 @@ func main() {
4747 }
4848 defer prov.Close()
4949
50- proxy, lspManager, showHandler, webCache := setupServices(cfg, creds)
50+ proxy, lspManager, webCache := setupServices(cfg, creds)
5151 defer proxy.Close()
5252 defer lspManager.StopAll(context.Background())
5353 if webCache != nil {
@@ -64,7 +64,6 @@ func main() {
6464 tui.New(prov, proxy, tools, providerCfg.Model),
6565 tea.WithFilter(tui.MouseEventFilter),
6666 )
67- showHandler.SetProgram(p)
6867 lspManager.SetCallback(func(absPath string, lines map[int]int) {
6968 p.Send(tui.LSPDiagnosticsMsg{FilePath: absPath, Lines: lines})
7069 })
@@ -107,7 +106,7 @@ func resolveProvider(cfg *config.Config, registry *provider.Registry) (string, c
107106 return name, pcfg
108107 }
109108
110-func setupServices(cfg *config.Config, creds *config.Credentials) (*mcp.Proxy, *lsp.Manager, *mcptools.ShowHandler, *store.Cache) {
109+func setupServices(cfg *config.Config, creds *config.Credentials) (*mcp.Proxy, *lsp.Manager, *store.Cache) {
111110 var mcpClient mcp.UpstreamClient
112111 if cfg.MCP.Upstream != "" {
113112 mcpClient = mcp.NewClient(cfg.MCP.Upstream)
@@ -123,9 +122,6 @@ func setupServices(cfg *config.Config, creds *config.Credentials) (*mcp.Proxy, *
123122 readHandler := mcptools.NewReadHandler(fileTracker, lspManager)
124123 proxy.RegisterTool(mcptools.NewReadTool(), readHandler.Handle)
125124
126- showHandler := mcptools.NewShowHandler()
127- proxy.RegisterTool(mcptools.NewShowTool(), showHandler.Handle)
128-
129125 proxy.RegisterTool(mcptools.NewGrepTool(), mcptools.MakeGrepHandler())
130126
131127 editHandler := mcptools.NewEditHandler(fileTracker, lspManager)
@@ -133,14 +129,12 @@ func setupServices(cfg *config.Config, creds *config.Credentials) (*mcp.Proxy, *
133129
134130 webCache := openWebCache(cfg)
135131
136- proxy.RegisterTool(mcptools.NewGitStatusTool(), mcptools.MakeGitStatusHandler())
137- proxy.RegisterTool(mcptools.NewGitDiffTool(), mcptools.MakeGitDiffHandler())
138132 proxy.RegisterTool(mcptools.NewWebFetchTool(), mcptools.MakeWebFetchHandler(webCache))
139133
140134 exaKey := creds.GetAPIKey("exa_ai")
141135 proxy.RegisterTool(mcptools.NewWebSearchTool(), mcptools.MakeWebSearchHandler(webCache, exaKey, ""))
142136
143- return proxy, lspManager, showHandler, webCache
137+ return proxy, lspManager, webCache
144138 }
145139
146140 func openWebCache(cfg *config.Config) *store.Cache {
docs/DESIGN.md+12−25
@@ -48,6 +48,7 @@ prepends to system prompt. Checks `~/.config/symb/AGENTS.md` too.
4848 - **OpenCode** — remote, API key auth. Model-specific endpoint routing.
4949 - Both use SSE streaming with retry on initial connection (3 retries, 429/5xx).
5050 - Single `ChatStream()` interface method replaces `Chat`/`ChatWithTools`/`Stream`.
51+- Deterministic JSON tool schemas, provider kv cache support
5152
5253 ### MCP (`internal/mcp`)
5354
@@ -59,28 +60,19 @@ Retry-After parsing.
5960
6061 3 tools registered:
6162
62-- **Open** — reads file, returns hashline-tagged content (`linenum:hash|content`),
63- sends to TUI editor. Path traversal prevention.
63+- **Read** — reads file, returns hashline-tagged content (`linenum:hash|content`). Path traversal prevention.
6464 - **Edit** — hash-anchored file editing (replace, insert, delete, create).
6565 Validates hashes before modifying. Returns fresh hashes after edit. Enforces
66- read-before-edit via `FileReadTracker`.
66+ read-before-edit via `FileReadTracker`. Includes LSP Diagnostics.
6767 - **Grep** — file/content search. Regex, gitignore-aware, case sensitivity,
6868 max results.
6969 - **WebSearch and Webfetch** -- read and search the web (search by exa.ai)
7070
71-### Supporting Packages
72-
73-- `internal/hashline` — SHA-256 truncated to 2 hex chars per line. Anchor
74- validation, range validation. 7 tests, 96.7% coverage.
75-- `internal/filesearch` — directory walker with `.gitignore` support, regex
76- matching, binary detection, 10MB size limit.
77-- `internal/config` — TOML config, JSON credentials, env overrides.
78-
7971 ### Git Integration
8072
81-- git **read** tools for the LLM: diff, status
82-- Editor displays diffs with syntax hl
83-- git markers in the number column for editted files in the editor
73+- **DEPRECATED** too complex and messes with syntax hl adding complexity with little value. Editor displays diffs with syntax hl
74+- git markers in the number column for editted files in the editor (needs work but does what it's meant to do)
75+- TODO: Read includes diff for the file (or diff status, we need to consider token usage) edit tool includes updated file diff after change
8476
8577 ### LSP Integration
8678
@@ -89,6 +81,12 @@ Retry-After parsing.
8981
9082 ## Features waiting implementation for current version:
9183
84+### Shell Execution Tool
85+
86+Run commands in sandbox (container isolation or restricted shell). Command
87+whitelisting. Output streaming to conversation.
88+Needs an undo.
89+
9290 ### Context management?
9391
9492 https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
@@ -129,7 +127,6 @@ Right (right aligned text)
129127 ### Git write commands and worktrees
130128
131129 - sandboxed git worktrees for agents edits.
132-- git **write** tools. (only after worktrees are functional)
133130
134131 ### Human-in-the-Middle Tool Approval
135132
@@ -137,16 +134,6 @@ Pause before executing tool calls. Show tool name + args in a dialog. User
137134 approves/rejects. Configurable per-tool permissions in `config.toml` (allow,
138135 ask, deny). Some tools (Read/Grep) default allow, mutations (Edit) default ask.
139136
140-### Delete tool and undo
141-
142-A simple file delete tool and a undo tool, undos delete or edit calls.
143-
144-### Shell Execution Tool
145-
146-Run commands in sandbox (container isolation or restricted shell). Command
147-whitelisting. Output streaming to conversation.
148-
149-
150137 ### Sub-Agent Tool
151138
152139 Spawn a child LLM turn scoped to a single task. Useful for parallel work
editfeedback.md+36−0
@@ -0,0 +1,36 @@
1+**Analysis of `edit.go`:**
2+
3+The core design is solid. Hashline anchoring works. What could be improved:
4+
5+**1. Error messages are too generic**
6+```go
7+// Current (line 83 in hashline.go):
8+"hash mismatch at line %d: expected %s, got %s"
9+```
10+Could include: actual line content, suggestion to re-read
11+
12+**2. No diff in response**
13+Currently returns full file with new hashes. Could add optional diff:
14+```
15+-3|old line
16++4|new line
17+```
18+
19+**3. Verbose JSON structure**
20+```json
21+{"replace": {"start": {"line": 5, "hash": "ab"}, "end": {...}}}
22+```
23+Could simplify to `"start": "5ab"` or similar shorthand
24+
25+**4. No "dry run" / validation mode**
26+LLM could check if edit is safe before committing
27+
28+**What I'd keep:**
29+- Read-before-edit enforcement ✅
30+- Hash validation ✅
31+- LSP diagnostics ✅
32+
33+**Quick wins:**
34+- Enhanced error messages with context
35+- Optional diff output in response
36+- Maybe shorthand anchor syntax (`"5ab"` vs `{"line":5,"hash":"ab"}`)
internal/llm/anthropic.md+1−19
@@ -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 Show with file_path*: "Here's main.go"
22+ - User: "Show me main.go" → *Use Read*: "Here's main.go"
2323
2424 **Professional objectivity:**
2525 - Prioritize technical accuracy over validation
@@ -50,15 +50,6 @@ The 2-char hex hash is a content fingerprint for that line. You need both the li
5050
5151 **You MUST Read a file before editing it.** Edit will reject changes to files you haven't read.
5252
53-Does NOT display in the editor — use Show for that.
54-
55-### `Show` — Display content in the editor pane
56-Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
57-
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)
61-
6253 ### `Grep` — Search files or content
6354 - Filename search: `{"pattern": "main\\.go", "content_search": false}`
6455 - Content search: `{"pattern": "func ProcessTurn", "content_search": true}`
@@ -120,8 +111,6 @@ One operation per call. After each edit, you get back the updated file with fres
120111 3. Call Edit with the exact anchors from step 1
121112 4. If chaining edits, use the fresh hashes from the Edit response for subsequent calls
122113
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.
124-
125114 **Debugging:** Get error → Grep for related code → Read → identify fix → Edit
126115
127116 ## Tool Usage Patterns
@@ -166,13 +155,6 @@ You: The issue is in `config/parser.go:31` — `cfg.Defaults` is accessed
166155 before nil check. Move the guard clause above line 31.
167156 ```
168157
169-**Example 3: User wants to see code**
170-```
171-User: Show me the config file
172-You: <Use Show with file_path="config/settings.go">
173-You: Displayed config/settings.go. Main struct starts at line 12.
174-```
175-
176158 ## Constraints
177159
178160 - **CWD-scoped**: All file operations are relative to current working directory
internal/llm/gemini.md+1−12
@@ -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 Show with file_path*: "Here's main.go"
39+- User: "Show me main.go" → *Use Read*: "Here's main.go"
4040
4141 **Professional objectivity:**
4242 - Prioritize technical accuracy over politeness
@@ -68,15 +68,6 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
6868
6969 **You MUST Read a file before editing it.** Edit will reject changes to unread files.
7070
71-Does NOT display in the editor — use Show for that.
72-
73-### `Show` — Display content in the editor pane
74-Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
75-
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)
79-
8071 ### `Grep` — Search files or content
8172 ```json
8273 {"pattern": "regex pattern", "content_search": false, "max_results": 100, "case_sensitive": false}
@@ -122,8 +113,6 @@ One operation per call. Returns updated file with fresh hashes after each edit.
122113 3. Call Edit with exact anchors from step 1
123114 4. For subsequent edits, use fresh hashes from Edit response
124115
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.
126-
127116 **Debugging:** Get error → Grep → Read → identify fix → Edit
128117
129118 ## Tool Usage Patterns
internal/llm/gpt.md+1−15
@@ -22,7 +22,7 @@ Q: "Is 11 prime?"
2222 A: "Yes"
2323
2424 Q: "Show me main.go"
25-A: [Uses Show with file_path] "Here's main.go"
25+A: [Uses Read] "Here's main.go"
2626 ```
2727
2828 ### Response Style
@@ -64,20 +64,6 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
6464
6565 **You MUST Read a file before editing it.** Edit will reject changes to unread files.
6666
67-Does NOT display in the editor — use Show for that.
68-
69-### `Show` — Display content in the editor pane
70-Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
71-
72-**Parameters:**
73-```json
74-{"content": "func main() {...}", "language": "go"}
75-{"content": "diff output...", "language": "diff"}
76-{"file_path": "main.go"}
77-```
78-
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-
8167 ### `Grep` — Search files or content
8268 ```json
8369 {"pattern": "regex_pattern", "content_search": false, "max_results": 100, "case_sensitive": false}
internal/llm/qwen.md+1−15
@@ -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 Show with file_path*: "Here's main.go"
23+- User: "Show me main.go" → *Use Read*: "Here's main.go"
2424
2525 **Be objective:**
2626 - Facts over reassurance
@@ -46,18 +46,6 @@ The 2-char hex hash is a content fingerprint. You need both line number and hash
4646 ```
4747 **You MUST Read a file before editing it.** Edit rejects changes to unread files.
4848
49-Does NOT display in the editor — use Show for that.
50-
51-### `Show` — Display content in the editor pane
52-Sends content to the user's editor pane with syntax highlighting. Provide either `content` or `file_path`, **not both**.
53-```json
54-{"content": "func main() {...}", "language": "go"}
55-{"content": "diff output...", "language": "diff"}
56-{"file_path": "main.go"}
57-```
58-
59-Use `file_path` to show files from disk (saves tokens, enables git gutter markers + LSP diagnostics, auto-detects language).
60-
6149 ### `Grep` — Search files/content
6250 ```json
6351 {"pattern": "search pattern", "content_search": false, "max_results": 100, "case_sensitive": false}
@@ -98,8 +86,6 @@ Hash mismatch = file changed since read → re-Read and retry. Use fresh hashes
9886 3. Call Edit with exact anchors
9987 4. Use fresh hashes from Edit response for next edit
10088
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.
102-
10389 **Debugging:** Get error → Grep → Read → Edit fix
10490
10591 ## Tool Usage
internal/mcptools/git.go+0−149
@@ -1,149 +0,0 @@
1-package mcptools
2-
3-import (
4- "bytes"
5- "context"
6- "encoding/json"
7- "fmt"
8- "os/exec"
9- "strings"
10-
11- "github.com/xonecas/symb/internal/mcp"
12-)
13-
14-// GitStatusArgs represents arguments for the GitStatus tool.
15-type GitStatusArgs struct {
16- Long bool `json:"long,omitempty"` // Use long format (default: false, short format)
17-}
18-
19-// GitDiffArgs represents arguments for the GitDiff tool.
20-type GitDiffArgs struct {
21- File string `json:"file,omitempty"` // Optional: specific file to diff
22- Staged bool `json:"staged,omitempty"` // Diff staged changes instead of unstaged
23-}
24-
25-// NewGitStatusTool creates the GitStatus tool definition.
26-func NewGitStatusTool() mcp.Tool {
27- return mcp.Tool{
28- Name: "GitStatus",
29- Description: "Show the working tree status. Returns modified, staged, and untracked files.",
30- InputSchema: json.RawMessage(`{
31- "type": "object",
32- "properties": {
33- "long": {"type": "boolean", "description": "Use long format output. Default: false (short format)"}
34- }
35- }`),
36- }
37-}
38-
39-// NewGitDiffTool creates the GitDiff tool definition.
40-func NewGitDiffTool() mcp.Tool {
41- return mcp.Tool{
42- Name: "GitDiff",
43- Description: "Show changes between working tree and index (unstaged), or between index and HEAD (staged). Returns unified diff output.",
44- InputSchema: json.RawMessage(`{
45- "type": "object",
46- "properties": {
47- "file": {"type": "string", "description": "Optional: specific file path to diff. If omitted, diffs all changed files."},
48- "staged": {"type": "boolean", "description": "If true, show staged (cached) changes. Default: false (unstaged changes)"}
49- }
50- }`),
51- }
52-}
53-
54-// runGit executes a git command and returns stdout, or a ToolResult error.
55-func runGit(ctx context.Context, args ...string) (string, *mcp.ToolResult) {
56- cmd := exec.CommandContext(ctx, "git", args...)
57- var stdout, stderr bytes.Buffer
58- cmd.Stdout = &stdout
59- cmd.Stderr = &stderr
60-
61- if err := cmd.Run(); err != nil {
62- // git diff returns exit code 1 when there are differences — that's not an error.
63- if cmd.ProcessState != nil && cmd.ProcessState.ExitCode() == 1 && stderr.Len() == 0 {
64- return stdout.String(), nil
65- }
66- msg := strings.TrimSpace(stderr.String())
67- if msg == "" {
68- msg = err.Error()
69- }
70- return "", &mcp.ToolResult{
71- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("git error: %s", msg)}},
72- IsError: true,
73- }
74- }
75- return stdout.String(), nil
76-}
77-
78-// MakeGitStatusHandler creates a handler for the GitStatus tool.
79-func MakeGitStatusHandler() mcp.ToolHandler {
80- return func(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
81- var args GitStatusArgs
82- if len(arguments) > 0 {
83- if err := json.Unmarshal(arguments, &args); err != nil {
84- return &mcp.ToolResult{
85- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
86- IsError: true,
87- }, nil
88- }
89- }
90-
91- gitArgs := []string{"status"}
92- if !args.Long {
93- gitArgs = append(gitArgs, "--short")
94- }
95-
96- out, errResult := runGit(ctx, gitArgs...)
97- if errResult != nil {
98- return errResult, nil
99- }
100-
101- if strings.TrimSpace(out) == "" {
102- out = "nothing to commit, working tree clean"
103- }
104-
105- return &mcp.ToolResult{
106- Content: []mcp.ContentBlock{{Type: "text", Text: out}},
107- }, nil
108- }
109-}
110-
111-// MakeGitDiffHandler creates a handler for the GitDiff tool.
112-func MakeGitDiffHandler() mcp.ToolHandler {
113- return func(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
114- var args GitDiffArgs
115- if len(arguments) > 0 {
116- if err := json.Unmarshal(arguments, &args); err != nil {
117- return &mcp.ToolResult{
118- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
119- IsError: true,
120- }, nil
121- }
122- }
123-
124- gitArgs := []string{"diff"}
125- if args.Staged {
126- gitArgs = append(gitArgs, "--cached")
127- }
128- if args.File != "" {
129- gitArgs = append(gitArgs, "--", args.File)
130- }
131-
132- out, errResult := runGit(ctx, gitArgs...)
133- if errResult != nil {
134- return errResult, nil
135- }
136-
137- if strings.TrimSpace(out) == "" {
138- label := "unstaged"
139- if args.Staged {
140- label = "staged"
141- }
142- out = fmt.Sprintf("no %s changes", label)
143- }
144-
145- return &mcp.ToolResult{
146- Content: []mcp.ContentBlock{{Type: "text", Text: out}},
147- }, nil
148- }
149-}
internal/mcptools/git_test.go+0−394
@@ -1,394 +0,0 @@
1-package mcptools
2-
3-import (
4- "context"
5- "encoding/json"
6- "os"
7- "os/exec"
8- "path/filepath"
9- "strings"
10- "testing"
11-
12- "github.com/xonecas/symb/internal/mcp"
13- "github.com/xonecas/symb/internal/tui/editor"
14-)
15-
16-// setupGitRepo creates a temp dir with an initialised git repo and returns
17-// the path along with a cleanup func that restores the original working dir.
18-func setupGitRepo(t *testing.T) (string, func()) {
19- t.Helper()
20-
21- dir := t.TempDir()
22- origDir, _ := os.Getwd()
23-
24- if err := os.Chdir(dir); err != nil {
25- t.Fatalf("chdir: %v", err)
26- }
27-
28- // Initialise a git repo with a first commit so HEAD exists.
29- for _, cmd := range [][]string{
30- {"git", "init"},
31- {"git", "config", "user.email", "test@test.com"},
32- {"git", "config", "user.name", "Test"},
33- } {
34- c := exec.Command(cmd[0], cmd[1:]...)
35- c.Dir = dir
36- if out, err := c.CombinedOutput(); err != nil {
37- t.Fatalf("setup %v: %s – %v", cmd, out, err)
38- }
39- }
40-
41- // Create an initial commit so we have HEAD.
42- initial := filepath.Join(dir, "init.txt")
43- if err := os.WriteFile(initial, []byte("init\n"), 0644); err != nil {
44- t.Fatal(err)
45- }
46- for _, cmd := range [][]string{
47- {"git", "add", "."},
48- {"git", "commit", "-m", "initial"},
49- } {
50- c := exec.Command(cmd[0], cmd[1:]...)
51- c.Dir = dir
52- if out, err := c.CombinedOutput(); err != nil {
53- t.Fatalf("setup %v: %s – %v", cmd, out, err)
54- }
55- }
56-
57- return dir, func() { os.Chdir(origDir) } //nolint:errcheck
58-}
59-
60-func callHandler(t *testing.T, handler func(context.Context, json.RawMessage) (*mcp.ToolResult, error), args interface{}) (string, bool) {
61- t.Helper()
62- raw, err := json.Marshal(args)
63- if err != nil {
64- t.Fatalf("marshal: %v", err)
65- }
66- result, err := handler(context.Background(), raw)
67- if err != nil {
68- t.Fatalf("handler error: %v", err)
69- }
70- text := ""
71- if len(result.Content) > 0 {
72- text = result.Content[0].Text
73- }
74- return text, result.IsError
75-}
76-
77-// ---------------------------------------------------------------------------
78-// GitStatus tests
79-// ---------------------------------------------------------------------------
80-
81-func TestGitStatusClean(t *testing.T) {
82- _, cleanup := setupGitRepo(t)
83- defer cleanup()
84-
85- handler := MakeGitStatusHandler()
86- text, isErr := callHandler(t, handler, GitStatusArgs{})
87- if isErr {
88- t.Fatalf("unexpected error: %s", text)
89- }
90- if !strings.Contains(text, "clean") {
91- t.Errorf("expected clean status, got: %s", text)
92- }
93-}
94-
95-func TestGitStatusWithChanges(t *testing.T) {
96- dir, cleanup := setupGitRepo(t)
97- defer cleanup()
98-
99- // Create an untracked file.
100- if err := os.WriteFile(filepath.Join(dir, "new.txt"), []byte("hello\n"), 0644); err != nil {
101- t.Fatal(err)
102- }
103-
104- handler := MakeGitStatusHandler()
105- text, isErr := callHandler(t, handler, GitStatusArgs{})
106- if isErr {
107- t.Fatalf("unexpected error: %s", text)
108- }
109- if !strings.Contains(text, "new.txt") {
110- t.Errorf("expected new.txt in status, got: %s", text)
111- }
112-}
113-
114-func TestGitStatusLongFormat(t *testing.T) {
115- _, cleanup := setupGitRepo(t)
116- defer cleanup()
117-
118- handler := MakeGitStatusHandler()
119- // long=true → long format which contains "On branch"
120- text, isErr := callHandler(t, handler, GitStatusArgs{Long: true})
121- if isErr {
122- t.Fatalf("unexpected error: %s", text)
123- }
124- // Long format includes "On branch" header.
125- if !strings.Contains(text, "On branch") {
126- t.Errorf("expected long format, got: %s", text)
127- }
128-}
129-
130-// ---------------------------------------------------------------------------
131-// GitDiff tests
132-// ---------------------------------------------------------------------------
133-
134-func TestGitDiffNoChanges(t *testing.T) {
135- _, cleanup := setupGitRepo(t)
136- defer cleanup()
137-
138- handler := MakeGitDiffHandler()
139- text, isErr := callHandler(t, handler, GitDiffArgs{})
140- if isErr {
141- t.Fatalf("unexpected error: %s", text)
142- }
143- if !strings.Contains(text, "no unstaged changes") {
144- t.Errorf("expected no changes message, got: %s", text)
145- }
146-}
147-
148-func TestGitDiffUnstaged(t *testing.T) {
149- dir, cleanup := setupGitRepo(t)
150- defer cleanup()
151-
152- // Modify the tracked file.
153- if err := os.WriteFile(filepath.Join(dir, "init.txt"), []byte("modified\n"), 0644); err != nil {
154- t.Fatal(err)
155- }
156-
157- handler := MakeGitDiffHandler()
158- text, isErr := callHandler(t, handler, GitDiffArgs{})
159- if isErr {
160- t.Fatalf("unexpected error: %s", text)
161- }
162- if !strings.Contains(text, "diff") {
163- t.Errorf("expected diff output, got: %s", text)
164- }
165- if !strings.Contains(text, "modified") {
166- t.Errorf("expected 'modified' in diff, got: %s", text)
167- }
168-}
169-
170-func TestGitDiffStaged(t *testing.T) {
171- dir, cleanup := setupGitRepo(t)
172- defer cleanup()
173-
174- // Modify and stage.
175- if err := os.WriteFile(filepath.Join(dir, "init.txt"), []byte("staged change\n"), 0644); err != nil {
176- t.Fatal(err)
177- }
178- cmd := exec.Command("git", "add", "init.txt")
179- cmd.Dir = dir
180- if out, err := cmd.CombinedOutput(); err != nil {
181- t.Fatalf("git add: %s – %v", out, err)
182- }
183-
184- handler := MakeGitDiffHandler()
185- text, isErr := callHandler(t, handler, GitDiffArgs{Staged: true})
186- if isErr {
187- t.Fatalf("unexpected error: %s", text)
188- }
189- if !strings.Contains(text, "staged change") {
190- t.Errorf("expected staged diff, got: %s", text)
191- }
192-}
193-
194-func TestGitDiffSpecificFile(t *testing.T) {
195- dir, cleanup := setupGitRepo(t)
196- defer cleanup()
197-
198- // Create and commit a second file, then modify both.
199- second := filepath.Join(dir, "second.txt")
200- if err := os.WriteFile(second, []byte("original\n"), 0644); err != nil {
201- t.Fatal(err)
202- }
203- for _, c := range [][]string{
204- {"git", "add", "second.txt"},
205- {"git", "commit", "-m", "add second"},
206- } {
207- cmd := exec.Command(c[0], c[1:]...)
208- cmd.Dir = dir
209- if out, err := cmd.CombinedOutput(); err != nil {
210- t.Fatalf("%v: %s – %v", c, out, err)
211- }
212- }
213-
214- // Modify both files.
215- os.WriteFile(filepath.Join(dir, "init.txt"), []byte("changed init\n"), 0644)
216- os.WriteFile(second, []byte("changed second\n"), 0644)
217-
218- handler := MakeGitDiffHandler()
219-
220- // Diff only second.txt.
221- text, isErr := callHandler(t, handler, GitDiffArgs{File: "second.txt"})
222- if isErr {
223- t.Fatalf("unexpected error: %s", text)
224- }
225- if !strings.Contains(text, "changed second") {
226- t.Errorf("expected second.txt diff, got: %s", text)
227- }
228- if strings.Contains(text, "changed init") {
229- t.Error("should not contain init.txt changes")
230- }
231-}
232-
233-func TestGitDiffNoStagedChanges(t *testing.T) {
234- _, cleanup := setupGitRepo(t)
235- defer cleanup()
236-
237- handler := MakeGitDiffHandler()
238- text, isErr := callHandler(t, handler, GitDiffArgs{Staged: true})
239- if isErr {
240- t.Fatalf("unexpected error: %s", text)
241- }
242- if !strings.Contains(text, "no staged changes") {
243- t.Errorf("expected no staged changes message, got: %s", text)
244- }
245-}
246-
247-// ---------------------------------------------------------------------------
248-// runGit edge cases
249-// ---------------------------------------------------------------------------
250-
251-func TestRunGitNotARepo(t *testing.T) {
252- dir := t.TempDir()
253- origDir, _ := os.Getwd()
254- defer os.Chdir(origDir) //nolint:errcheck
255- os.Chdir(dir) //nolint:errcheck
256-
257- handler := MakeGitStatusHandler()
258- text, isErr := callHandler(t, handler, GitStatusArgs{})
259- if !isErr {
260- t.Errorf("expected error outside git repo, got: %s", text)
261- }
262- if !strings.Contains(text, "git error") {
263- t.Errorf("expected git error message, got: %s", text)
264- }
265-}
266-
267-// ---------------------------------------------------------------------------
268-// ParseDiffMarkers tests
269-// ---------------------------------------------------------------------------
270-
271-func TestParseDiffMarkersEmpty(t *testing.T) {
272- m := ParseDiffMarkers("")
273- if m != nil {
274- t.Errorf("expected nil for empty diff, got %v", m)
275- }
276-}
277-
278-func TestParseDiffMarkersAdd(t *testing.T) {
279- // Pure addition: 3 new lines starting at line 5.
280- diff := `diff --git a/file.go b/file.go
281---- a/file.go
282-+++ b/file.go
283-@@ -4,0 +5,3 @@ func foo() {
284-+line1
285-+line2
286-+line3
287-`
288- m := ParseDiffMarkers(diff)
289- if len(m) != 3 {
290- t.Fatalf("expected 3 markers, got %d: %v", len(m), m)
291- }
292- for _, row := range []int{4, 5, 6} { // 0-indexed
293- if m[row] != editor.GutterAdd {
294- t.Errorf("row %d: expected GutterAdd, got %v", row, m[row])
295- }
296- }
297-}
298-
299-func TestParseDiffMarkersDelete(t *testing.T) {
300- // Pure deletion: 2 old lines removed, new file continues at line 10.
301- diff := `diff --git a/file.go b/file.go
302---- a/file.go
303-+++ b/file.go
304-@@ -8,2 +10,0 @@ func bar() {
305--old1
306--old2
307-`
308- m := ParseDiffMarkers(diff)
309- if len(m) != 1 {
310- t.Fatalf("expected 1 marker, got %d: %v", len(m), m)
311- }
312- // newStart=10, newCount=0 → mark row 10-1=9 (0-indexed)
313- if m[9] != editor.GutterDelete {
314- t.Errorf("row 9: expected GutterDelete, got %v", m[9])
315- }
316-}
317-
318-func TestParseDiffMarkersChange(t *testing.T) {
319- // Modification: 2 old lines replaced by 3 new lines starting at line 7.
320- diff := `diff --git a/file.go b/file.go
321---- a/file.go
322-+++ b/file.go
323-@@ -7,2 +7,3 @@ func baz() {
324--old
325--old2
326-+new1
327-+new2
328-+new3
329-`
330- m := ParseDiffMarkers(diff)
331- if len(m) != 3 {
332- t.Fatalf("expected 3 markers, got %d: %v", len(m), m)
333- }
334- for _, row := range []int{6, 7, 8} { // 0-indexed
335- if m[row] != editor.GutterChange {
336- t.Errorf("row %d: expected GutterChange, got %v", row, m[row])
337- }
338- }
339-}
340-
341-func TestParseDiffMarkersMultipleHunks(t *testing.T) {
342- diff := `diff --git a/file.go b/file.go
343---- a/file.go
344-+++ b/file.go
345-@@ -1,0 +2,1 @@
346-+added
347-@@ -10,1 +12,1 @@
348--old
349-+changed
350-`
351- m := ParseDiffMarkers(diff)
352- if len(m) != 2 {
353- t.Fatalf("expected 2 markers, got %d: %v", len(m), m)
354- }
355- if m[1] != editor.GutterAdd { // line 2, 0-indexed = 1
356- t.Errorf("row 1: expected GutterAdd, got %v", m[1])
357- }
358- if m[11] != editor.GutterChange { // line 12, 0-indexed = 11
359- t.Errorf("row 11: expected GutterChange, got %v", m[11])
360- }
361-}
362-
363-func TestParseDiffMarkersSingleLineNoComma(t *testing.T) {
364- // When count is 1, git omits the comma: @@ -5 +5 @@
365- diff := `@@ -5 +5 @@
366--old
367-+new
368-`
369- m := ParseDiffMarkers(diff)
370- if len(m) != 1 {
371- t.Fatalf("expected 1 marker, got %d: %v", len(m), m)
372- }
373- if m[4] != editor.GutterChange { // line 5, 0-indexed = 4
374- t.Errorf("row 4: expected GutterChange, got %v", m[4])
375- }
376-}
377-
378-func TestGitFileMarkersIntegration(t *testing.T) {
379- dir, cleanup := setupGitRepo(t)
380- defer cleanup()
381-
382- // Modify the tracked file.
383- if err := os.WriteFile(filepath.Join(dir, "init.txt"), []byte("changed\n"), 0644); err != nil {
384- t.Fatal(err)
385- }
386-
387- m := GitFileMarkers(context.Background(), "init.txt")
388- if m == nil {
389- t.Fatal("expected markers for modified file, got nil")
390- }
391- if _, ok := m[0]; !ok {
392- t.Errorf("expected marker on row 0, got %v", m)
393- }
394-}
internal/mcptools/open.go+1−9
@@ -20,19 +20,11 @@ type ReadArgs struct {
2020 End int `json:"end,omitempty"` // Optional: end line (1-indexed)
2121 }
2222
23-// ShowMsg is the message sent to TUI to display content in the editor pane.
24-type ShowMsg struct {
25- Content string
26- Language string
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
29-}
30-
3123 // NewReadTool creates the Read tool definition.
3224 func NewReadTool() mcp.Tool {
3325 return mcp.Tool{
3426 Name: "Read",
35- 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.`,
27+ 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.`,
3628 InputSchema: json.RawMessage(`{
3729 "type": "object",
3830 "properties": {
internal/mcptools/show.go+0−114
@@ -1,114 +0,0 @@
1-package mcptools
2-
3-import (
4- "context"
5- "encoding/json"
6- "fmt"
7- "os"
8- "path/filepath"
9-
10- tea "charm.land/bubbletea/v2"
11- "github.com/xonecas/symb/internal/mcp"
12-)
13-
14-// ShowArgs represents arguments for the Show tool.
15-type ShowArgs struct {
16- Content string `json:"content,omitempty"`
17- Language string `json:"language,omitempty"`
18- FilePath string `json:"file_path,omitempty"`
19-}
20-
21-// NewShowTool creates the Show tool definition.
22-func NewShowTool() mcp.Tool {
23- return mcp.Tool{
24- Name: "Show",
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.`,
26- InputSchema: json.RawMessage(`{
27- "type": "object",
28- "properties": {
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."}
32- },
33- "oneOf": [
34- {"required": ["content"]},
35- {"required": ["file_path"]}
36- ]
37- }`),
38- }
39-}
40-
41-// ShowHandler handles Show tool calls and sends content to the TUI editor.
42-type ShowHandler struct {
43- program *tea.Program
44-}
45-
46-// NewShowHandler creates a handler for the Show tool.
47-func NewShowHandler() *ShowHandler {
48- return &ShowHandler{}
49-}
50-
51-// SetProgram sets the tea.Program instance after it's created.
52-func (h *ShowHandler) SetProgram(program *tea.Program) {
53- h.program = program
54-}
55-
56-// Handle implements the mcp.ToolHandler interface.
57-func (h *ShowHandler) Handle(_ context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
58- var args ShowArgs
59- if err := json.Unmarshal(arguments, &args); err != nil {
60- return &mcp.ToolResult{
61- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
62- IsError: true,
63- }, nil
64- }
65-
66- if args.Content != "" && args.FilePath != "" {
67- return &mcp.ToolResult{
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"}},
75- IsError: true,
76- }, nil
77- }
78-
79- content := args.Content
80- 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-
98- if language == "" {
99- language = "text"
100- }
101-
102- if h.program != nil {
103- h.program.Send(ShowMsg{
104- Content: content,
105- Language: language,
106- FilePath: args.FilePath,
107- AbsPath: absPath,
108- })
109- }
110-
111- return &mcp.ToolResult{
112- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Displayed content in editor (%s)", language)}},
113- }, nil
114-}
internal/tui/editor/editor.go+0−9
@@ -49,9 +49,6 @@ type Model struct {
Cut short: this commit's diff is over 1000 lines.
internal/tui/editor/highlight.go+0−10
Cut short: this commit's diff is over 1000 lines.
internal/tui/editor/view.go+8−25
Cut short: this commit's diff is over 1000 lines.
internal/tui/gitdiff.go+1−1
Cut short: this commit's diff is over 1000 lines.
internal/tui/gitdiff_test.go+184−0
Cut short: this commit's diff is over 1000 lines.
internal/tui/mouse.go+10−52
Cut short: this commit's diff is over 1000 lines.
internal/tui/update.go+0−25
Cut short: this commit's diff is over 1000 lines.