xonecas.io
62159
Sy

symb / commit 51235ac

fix: codebase health

xonecas2026-02-12 51235ac25218bbc2f98db5fb38664977d366669b parent 893874a

16 files changed

.golangci.yml+19−21
@@ -1,35 +1,33 @@
11 run:
22 timeout: 5m
3- go: '1.23'
43
54 linters:
65 enable:
7- - errcheck # Check for unchecked errors
8- - gosimple # Simplify code
9- - govet # Vet examines Go source code
10- - ineffassign # Detect ineffectual assignments
11- - staticcheck # Static analysis
12- - unused # Check for unused constants, variables, functions
13- - gofmt # Check formatting
14- - goimports # Check imports
15- - misspell # Check for commonly misspelled words
16- - revive # Fast, configurable, extensible linter
17- - stylecheck # Replacement for golint
18- - unconvert # Remove unnecessary type conversions
19- - unparam # Report unused function parameters
20- - goconst # Find repeated strings that could be constants
21- - gocyclo # Check cyclomatic complexity
22- - dupl # Check for duplicate code
23- - godot # Check if comments end in a period
24- - gosec # Security problems
6+ - errcheck # Check for unchecked errors
7+ - gosimple # Simplify code
8+ - govet # Vet examines Go source code
9+ - ineffassign # Detect ineffectual assignments
10+ - staticcheck # Static analysis
11+ - unused # Check for unused constants, variables, functions
12+ - gofmt # Check formatting
13+ - goimports # Check imports
14+ - misspell # Check for commonly misspelled words
15+ - revive # Fast, configurable, extensible linter
16+ - stylecheck # Replacement for golint
17+ - unconvert # Remove unnecessary type conversions
18+ - unparam # Report unused function parameters
19+ - goconst # Find repeated strings that could be constants
20+ - gocyclo # Check cyclomatic complexity
21+ - dupl # Check for duplicate code
22+ - gosec # Security problems
2523
2624 linters-settings:
2725 gocyclo:
2826 min-complexity: 15
29-
27+
3028 dupl:
3129 threshold: 100
32-
30+
3331 goconst:
3432 min-len: 3
3533 min-occurrences: 3
Makefile+1−1
@@ -14,7 +14,7 @@ test:
1414
1515 # Run linter
1616 lint:
17- $$(go env GOPATH)/bin/golangci-lint run ./...
17+ $$(go env GOPATH)/bin/golangci-lint run ./cmd/... ./internal/...
1818
1919 # Clean build artifacts
2020 clean:
cmd/symb/main.go+7−8
@@ -90,15 +90,11 @@ func main() {
9090 }
9191 defer proxy.Close()
9292
93- // Create program pointer that will be set after program creation
94- var p *tea.Program
95-
96- // Register local tools that need program reference (before listing tools)
93+ // Register local tools
9794 openForUserTool := mcp_tools.NewOpenForUserTool()
98- openForUserHandler := mcp_tools.MakeOpenForUserHandler(&p)
99- proxy.RegisterTool(openForUserTool, openForUserHandler)
95+ openForUserHandler := mcp_tools.NewOpenForUserHandler()
96+ proxy.RegisterTool(openForUserTool, openForUserHandler.Handle)
10097
101- // Register grep tool
10298 grepTool := mcp_tools.NewGrepTool()
10399 grepHandler := mcp_tools.MakeGrepHandler()
104100 proxy.RegisterTool(grepTool, grepHandler)
@@ -111,12 +107,15 @@ func main() {
111107 }
112108
113109 // Create the BubbleTea program
114- p = tea.NewProgram(
110+ p := tea.NewProgram(
115111 tui.New(prov, proxy, tools),
116112 tea.WithAltScreen(),
117113 tea.WithMouseCellMotion(),
118114 )
119115
116+ // Set program reference for tools that need it
117+ openForUserHandler.SetProgram(p)
118+
120119 // Run the program
121120 if _, err := p.Run(); err != nil {
122121 fmt.Printf("Error running symb: %v\n", err)
docs/DESIGN.md+28−3
@@ -160,13 +160,38 @@ Confidence Level: High for a prototype. The ecosystem is ready.
160160
161161 # TODO:
162162
163-- TUI is extremly lagging, if I scroll or hold a key down. Cursor blocks scrolling, needs to follow it. ** MAJOR ISSUE **
163+- Grep is not matching pathname:
164164
165-- Enter on editor area send empty message. Both text areas are Focused, should be mutually exclusive.
165+```
166+The Grep tool was called with the following arguments:
167+
168+- `pattern`: `"mcp_tools.go"`
169+- `content_search`: `false` (filename search, not content grep)
170+- `case_sensitive`: `false` (default, case-insensitive)
171+- `max_results`: `100` (default)
172+
173+This means the tool was searching for files named
174+`mcp_tools.go` (or similar, due to fuzzy matching) in the
175+current directory and tracked paths (while respecting
176+`.gitignore`). Let me know if you'd like to tweak these
177+parameters!
178+```
179+
180+- Show tool call arguments expanded:
181+
182+```
183+ Grep(pattern="...", ...)
184+```
185+
186+- Open() should return the openned content to the LLM, and still open the snippet in the editor.
187+
188+- Add Prompt, and AGENTS.md support.
189+
190+- Make file references clickable in coversation (including tool calls output.)
166191
167192 - Copy text selection to clipboard (shift + arrows) then (ctrl + shift + c)
168193
169-- file searching and opening, buffer switching. // do I even want this, just make llm tools and ask it.
194+- file searching and opening, buffer switching. do I even want this, just make llm tools and ask it.
170195
171196 - streamed assistant response
172197
docs/TUI_TESTING.md+4−4
@@ -2,7 +2,7 @@
22
33 ## Overview
44
5-Zoea Nova's TUI test suite uses three complementary testing approaches:
5+Symb's TUI test suite uses three complementary testing approaches:
66 1. **Unit tests** - Model state and business logic
77 2. **Golden file tests** - Visual regression testing
88 3. **Integration tests** - End-to-end user flows with teatest
@@ -322,7 +322,7 @@ This prevents the Unicode overlap bug previously fixed in commit fb1d0b6.
322322
323323 1. **Test in primary terminal** (Alacritty, Kitty, WezTerm recommended):
324324 ```bash
325- ./bin/zoea --offline
325+ ./bin/symb
326326 ```
327327
328328 2. **Verify spinner animation:**
@@ -829,9 +829,9 @@ Decorative elements (icons, indicators) must be rendered OUTSIDE styled areas to
829829 ### 4. Tests Don't Replace Manual Verification
830830 Always run the actual TUI application to verify visual changes. Tests validate logic and catch regressions, but human eyes catch visual issues tests miss.
831831
832-Use offline mode for safe UI testing without connecting to the live game server:
832+Run the TUI application to verify visual changes:
833833 ```bash
834-./bin/zoea -offline
834+./bin/symb
835835 ```
836836
837837 ### 5. Integration Tests Need Quit Pattern
internal/constants/constants.go+1−1
@@ -51,4 +51,4 @@ package constants
5151 // - fruity, autumn, friendly, colorful, tango, algol, arduino
5252 // - base16-snazzy, borland, emacs, pygments, rainbow_dash
5353 // - and more...
54-const SyntaxTheme = "monokai"
54+const SyntaxTheme = "native"
internal/llm/loop.go+1−0
@@ -1,3 +1,4 @@
1+// Package llm implements the LLM interaction loop with tool calling support.
12 package llm
23
34 import (
internal/mcp/proxy.go+1−0
@@ -1,3 +1,4 @@
1+// Package mcp implements Model Context Protocol client and proxy functionality.
12 package mcp
23
34 import (
internal/mcp_tools/grep.go+1−0
@@ -1,3 +1,4 @@
1+// Package mcp_tools provides local MCP tool implementations.
12 package mcp_tools
23
34 import (
internal/mcp_tools/open.go+105−93
@@ -56,118 +56,130 @@ func NewOpenForUserTool() mcp.Tool {
5656 }
5757 }
5858
59-// MakeOpenForUserHandler creates a handler for Open tool.
60-// programPtr should point to the tea.Program instance (can be set after creation).
61-func MakeOpenForUserHandler(programPtr **tea.Program) mcp.ToolHandler {
62- return func(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
63- var args OpenForUserArgs
64- if err := json.Unmarshal(arguments, &args); err != nil {
65- return &mcp.ToolResult{
66- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
67- IsError: true,
68- }, nil
69- }
59+// OpenForUserHandler handles Open tool calls and sends messages to the TUI program.
60+type OpenForUserHandler struct {
61+ program *tea.Program
62+}
7063
71- if args.File == "" {
72- return &mcp.ToolResult{
73- Content: []mcp.ContentBlock{{Type: "text", Text: "File path cannot be empty"}},
74- IsError: true,
75- }, nil
76- }
64+// NewOpenForUserHandler creates a handler for Open tool.
65+func NewOpenForUserHandler() *OpenForUserHandler {
66+ return &OpenForUserHandler{}
67+}
7768
78- // Security: Convert to absolute path and validate
79- absPath, err := filepath.Abs(args.File)
80- if err != nil {
81- return &mcp.ToolResult{
82- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid file path: %v", err)}},
83- IsError: true,
84- }, nil
69+// SetProgram sets the tea.Program instance after it's created.
70+func (h *OpenForUserHandler) SetProgram(program *tea.Program) {
71+ h.program = program
72+}
73+
74+// Handle implements the mcp.ToolHandler interface.
75+func (h *OpenForUserHandler) Handle(ctx context.Context, arguments json.RawMessage) (*mcp.ToolResult, error) {
76+ var args OpenForUserArgs
77+ if err := json.Unmarshal(arguments, &args); err != nil {
78+ return &mcp.ToolResult{
79+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid arguments: %v", err)}},
80+ IsError: true,
81+ }, nil
82+ }
83+
84+ if args.File == "" {
85+ return &mcp.ToolResult{
86+ Content: []mcp.ContentBlock{{Type: "text", Text: "File path cannot be empty"}},
87+ IsError: true,
88+ }, nil
89+ }
90+
91+ // Security: Convert to absolute path and validate
92+ absPath, err := filepath.Abs(args.File)
93+ if err != nil {
94+ return &mcp.ToolResult{
95+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid file path: %v", err)}},
96+ IsError: true,
97+ }, nil
98+ }
99+
100+ // Get current working directory for validation
101+ workingDir, err := os.Getwd()
102+ if err != nil {
103+ return &mcp.ToolResult{
104+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Failed to get working directory: %v", err)}},
105+ IsError: true,
106+ }, nil
107+ }
108+
109+ // Security: Prevent path traversal - only allow files within or below working directory
110+ relPath, err := filepath.Rel(workingDir, absPath)
111+ if err != nil || strings.HasPrefix(relPath, "..") || filepath.IsAbs(relPath) {
112+ return &mcp.ToolResult{
113+ Content: []mcp.ContentBlock{{Type: "text", Text: "Access denied: path outside working directory"}},
114+ IsError: true,
115+ }, nil
116+ }
117+
118+ // Read file content
119+ content, err := os.ReadFile(absPath)
120+ if err != nil {
121+ return &mcp.ToolResult{
122+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Failed to read file: %v", err)}},
123+ IsError: true,
124+ }, nil
125+ }
126+
127+ lines := strings.Split(string(content), "\n")
128+
129+ // Extract line range if specified
130+ var selectedContent string
131+ if args.Start > 0 || args.End > 0 {
132+ start := args.Start
133+ end := args.End
134+
135+ // Default start to 1 if not specified
136+ if start <= 0 {
137+ start = 1
85138 }
86139
87- // Get current working directory for validation
88- workingDir, err := os.Getwd()
89- if err != nil {
140+ // Validate start is in range
141+ if start < 1 || start > len(lines) {
90142 return &mcp.ToolResult{
91- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Failed to get working directory: %v", err)}},
143+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Start line %d out of range (file has %d lines)", start, len(lines))}},
92144 IsError: true,
93145 }, nil
94146 }
95147
96- // Security: Prevent path traversal - only allow files within or below working directory
97- relPath, err := filepath.Rel(workingDir, absPath)
98- if err != nil || strings.HasPrefix(relPath, "..") || filepath.IsAbs(relPath) {
99- return &mcp.ToolResult{
100- Content: []mcp.ContentBlock{{Type: "text", Text: "Access denied: path outside working directory"}},
101- IsError: true,
102- }, nil
148+ // Default end to end of file if not specified or out of range
149+ if end <= 0 || end > len(lines) {
150+ end = len(lines)
103151 }
104152
105- // Read file content
106- content, err := os.ReadFile(absPath)
107- if err != nil {
153+ // Validate range
154+ if start > end {
108155 return &mcp.ToolResult{
109- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Failed to read file: %v", err)}},
156+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid range: start (%d) > end (%d)", start, end)}},
110157 IsError: true,
111158 }, nil
112159 }
113160
114- lines := strings.Split(string(content), "\n")
115-
116- // Extract line range if specified
117- var selectedContent string
118- if args.Start > 0 || args.End > 0 {
119- start := args.Start
120- end := args.End
121-
122- // Default start to 1 if not specified
123- if start <= 0 {
124- start = 1
125- }
126-
127- // Validate start is in range
128- if start < 1 || start > len(lines) {
129- return &mcp.ToolResult{
130- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Start line %d out of range (file has %d lines)", start, len(lines))}},
131- IsError: true,
132- }, nil
133- }
134-
135- // Default end to end of file if not specified or out of range
136- if end <= 0 || end > len(lines) {
137- end = len(lines)
138- }
139-
140- // Validate range
141- if start > end {
142- return &mcp.ToolResult{
143- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Invalid range: start (%d) > end (%d)", start, end)}},
144- IsError: true,
145- }, nil
146- }
147-
148- // Extract range (convert to 0-indexed)
149- selectedContent = strings.Join(lines[start-1:end], "\n")
150- } else {
151- selectedContent = string(content)
152- }
153-
154- // Detect language from file extension
155- language := detectLanguage(args.File)
161+ // Extract range (convert to 0-indexed)
162+ selectedContent = strings.Join(lines[start-1:end], "\n")
163+ } else {
164+ selectedContent = string(content)
165+ }
156166
157- // Send message to TUI to update editor
158- if programPtr != nil && *programPtr != nil {
159- (*programPtr).Send(OpenForUserMsg{
160- Content: selectedContent,
161- Language: language,
162- FilePath: args.File,
163- })
164- }
167+ // Detect language from file extension
168+ language := detectLanguage(args.File)
165169
166- return &mcp.ToolResult{
167- Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Opened %s in editor", args.File)}},
168- IsError: false,
169- }, nil
170+ // Send message to TUI to update editor
171+ if h.program != nil {
172+ h.program.Send(OpenForUserMsg{
173+ Content: selectedContent,
174+ Language: language,
175+ FilePath: args.File,
176+ })
170177 }
178+
179+ return &mcp.ToolResult{
180+ Content: []mcp.ContentBlock{{Type: "text", Text: fmt.Sprintf("Opened %s in editor", args.File)}},
181+ IsError: false,
182+ }, nil
171183 }
172184
173185 // detectLanguage returns the Chroma language identifier based on file extension.
internal/provider/openai_common.go+0−44
@@ -2,7 +2,6 @@ package provider
22
33 import (
44 "encoding/json"
5- "errors"
65 "strings"
76
87 "github.com/rs/zerolog/log"
@@ -75,49 +74,6 @@ func toOpenAIMessages(messages []Message) []openai.ChatCompletionMessage {
7574 return result
7675 }
7776
78-// validateOpenAIMessages ensures message structure meets OpenAI API requirements:
79-// 1. At least one non-system message exists
80-// 2. Conversation ends with user message (if expecting completion)
81-// 3. No consecutive assistant messages without user messages between them
82-//
83-// Returns error if validation fails.
84-func validateOpenAIMessages(messages []openai.ChatCompletionMessage) error {
85- if len(messages) == 0 {
86- return errors.New("messages array is empty")
87- }
88-
89- // Count message types
90- hasUser := false
91- hasAssistant := false
92- lastRole := ""
93-
94- for _, msg := range messages {
95- if msg.Role == "user" {
96- hasUser = true
97- }
98- if msg.Role == "assistant" {
99- hasAssistant = true
100- // Check for consecutive assistant messages
101- if lastRole == "assistant" {
102- log.Warn().Msg("OpenAI: Consecutive assistant messages detected")
103- }
104- }
105- lastRole = msg.Role
106- }
107-
108- // If we have assistant messages but no user messages, that's invalid
109- if hasAssistant && !hasUser {
110- return errors.New("conversation has assistant messages but no user messages")
111- }
112-
113- // If last message is assistant (and we're expecting a completion), that's invalid
114- if lastRole == "assistant" {
115- log.Warn().Msg("OpenAI: Conversation ends with assistant message - may cause issues")
116- }
117-
118- return nil
119-}
120-
12177 // mergeSystemMessagesOpenAI merges system messages intelligently while preserving conversation flow.
12278 //
12379 // Strategy:
internal/tui/testdata/TestLayout/120x40/ANSI.golden+1−1
@@ -32,7 +32,7 @@
3232 │
3333 │
3434 │
35- ├───────────────────────────────────────────────────────────
35+ │───────────────────────────────────────────────────────────
3636 │Type a message...
3737 │
3838 │
internal/tui/testdata/TestLayout/120x40/Stripped.golden+1−1
@@ -32,7 +32,7 @@
3232 │
3333 │
3434 │
35- ├───────────────────────────────────────────────────────────
35+ │───────────────────────────────────────────────────────────
3636 │Type a message...
3737 │
3838 │
internal/tui/testdata/TestLayout/80x24/ANSI.golden+1−1
@@ -16,7 +16,7 @@
1616 │
1717 │
1818 │
19- ├───────────────────────────────────────
19+ │───────────────────────────────────────
2020 │Type a message...
2121 │
2222 │
internal/tui/testdata/TestLayout/80x24/Stripped.golden+1−1
@@ -16,7 +16,7 @@
1616 │
1717 │
1818 │
19- ├───────────────────────────────────────
19+ │───────────────────────────────────────
2020 │Type a message...
2121 │
2222 │
internal/tui/tui.go+3−5
@@ -51,13 +51,11 @@ type Model struct {
5151 customHalfWidth int // Custom half width (0 = use default calculated value)
5252
5353 // Wrap cache to avoid re-wrapping unchanged text
54- wrapCache map[string][]string
55- wrapCacheKey string // Key for current conversation state
54+ wrapCache map[string][]string
5655
5756 // Pre-allocated styles to avoid repeated allocations
58- borderStyle lipgloss.Style
59- selectionStyle lipgloss.Style
60- conversationWidth int // Track width for style invalidation
57+ borderStyle lipgloss.Style
58+ selectionStyle lipgloss.Style
6159 }
6260
6361 // New creates a new TUI model