xonecas.io
62159
Sy

symb / commit 3230270

fix: codebase health

xonecas2026-02-14 3230270954c7711835d879ac4b3904540d2e5d1c parent a97ccdd

7 files changed

docs/DESIGN.md+25−3
@@ -41,6 +41,11 @@ Prompt system: model-specific base prompts (Claude, Gemini, Qwen, GPT).
4141 `AGENTS.md` support: walks directory tree upward collecting all AGENTS.md files,
4242 prepends to system prompt. Checks `~/.config/symb/AGENTS.md` too.
4343
44+**TODO**: Extract common parts into one file, use templates to compose final prompt.
45+ - symb.md: symb specific prompt text
46+ - <model name>-<segment name>.md: model specific instructions
47+ - base: common model instructions. and template tags to insert symb and model specific segments.
48+
4449 ### Providers (`internal/provider`)
4550
4651 - **Ollama** — local, OpenAI-compatible `/v1` endpoint. Extracts reasoning from
@@ -56,7 +61,7 @@ Proxy merges local tool handlers with optional upstream MCP server (HTTP
5661 Streamable-HTTP transport, SSE support, session tracking). Retry with
5762 Retry-After parsing.
5863
59-### Tools (`internal/mcp_tools`)
64+### Tools (`internal/mcptools`)
6065
6166 3 tools registered:
6267
@@ -70,7 +75,6 @@ Retry-After parsing.
7075
7176 ### Git Integration
7277
73-- **DEPRECATED** too complex and messes with syntax hl adding complexity with little value. Editor displays diffs with syntax hl
7478 - git markers in the number column for editted files in the editor (needs work but does what it's meant to do)
7579 - TODO: Read includes diff for the file (or diff status, we need to consider token usage) edit tool includes updated file diff after change
7680
@@ -81,6 +85,18 @@ Retry-After parsing.
8185
8286 ## Features waiting implementation for current version:
8387
88+### Basic Session storage
89+
90+- table for conversation messages
91+- each message includes all tool calls
92+- opening the app opens a new session (more controls later). Same behaviour
93+- this table will be used for undo history. We need to think how to reverse tool calls. Consider best way to track undo's **NEEDS DESIGN WORK**
94+
95+### Undo!
96+
97+- User should be able to undo conversation turns. The most recent entry should show a clear clickable area labelled undo.
98+- Clicking undo reverses context history, tool calls, filesystem changes, file changes. Resets the conversation to that exact point
99+
84100 ### Shell Execution Tool
85101
86102 Run commands in sandbox (container isolation or restricted shell). Command
@@ -96,12 +112,18 @@ https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Ma
96112 Parse project with tree-sitter for structural awareness. Feed relevant
97113 symbols/scope to LLM as auto-context instead of whole files.
98114
99-### Tool improvements:
115+### Conversation log improvements:
100116
101117 Update hover iteraction on tool responses for ux and tool call tui output.
102118
103119 - Show tool call arguments expanded: `Grep(pattern="...", ...)`, for all tools.
104120 - Show LSP diagnostics after each mutation call in conversation log, as part of the tool response.
121+- Render responses with markdown syntax. Improve markdown syntax hl overall
122+- Smarter click on tool response:
123+ - Click on Read response: Opens the file, with cursor at read start.
124+ - Click on Edit response: Opens the editted file, with cursor at the change
125+ - Click on Grep: Show output in full, each match is clickable to open the file with cursor at the match.
126+ - Click on Shell tool, show output in full, try to parse filenames into clickable aread that opens
105127
106128 ### Statusbar implementation
107129
internal/highlight/highlight.go+10−5
@@ -1,4 +1,6 @@
1-package editor
1+// Package highlight provides syntax highlighting via Chroma, decoupled from any
2+// specific TUI component.
3+package highlight
24
35 import (
46 "fmt"
@@ -12,7 +14,7 @@ import (
1214 )
1315
1416 // ---------------------------------------------------------------------------
15-// Highlight cache (global, shared across instances)
17+// Highlight cache (global, shared across callers)
1618 // ---------------------------------------------------------------------------
1719
1820 var (
@@ -20,7 +22,10 @@ var (
2022 hlCacheMu sync.RWMutex
2123 )
2224
23-func cachedHighlight(text, language, theme, bgHex string) string {
25+// CachedHighlight returns an ANSI-highlighted version of text using the given
26+// Chroma language and theme. bgHex ("#rrggbb") is injected after every ANSI
27+// reset so the background color is never lost.
28+func CachedHighlight(text, language, theme, bgHex string) string {
2429 cacheKey := language + ":" + theme + ":" + bgHex + ":" + text
2530 hlCacheMu.RLock()
2631 if v, ok := hlCache[cacheKey]; ok {
@@ -91,9 +96,9 @@ func hexNibble(c byte) int {
9196 return 0
9297 }
9398
94-// themeBg extracts the background hex color from a Chroma style.
99+// ThemeBg extracts the background hex color from a Chroma style.
95100 // Returns "" if no background is set.
96-func themeBg(theme string) string {
101+func ThemeBg(theme string) string {
97102 sty := styles.Get(theme)
98103 if sty == nil {
99104 return ""
internal/highlight/language.go+81−0
@@ -0,0 +1,81 @@
1+package highlight
2+
3+import (
4+ "path/filepath"
5+ "strings"
6+)
7+
8+// DetectLanguage returns the Chroma language identifier based on file extension.
9+func DetectLanguage(path string) string {
10+ // Map common extensions to Chroma language identifiers
11+ languageMap := map[string]string{
12+ ".go": "go",
13+ ".py": "python",
14+ ".js": "javascript",
15+ ".ts": "typescript",
16+ ".jsx": "jsx",
17+ ".tsx": "tsx",
18+ ".java": "java",
19+ ".c": "c",
20+ ".cpp": "cpp",
21+ ".cc": "cpp",
22+ ".h": "c",
23+ ".hpp": "cpp",
24+ ".cs": "csharp",
25+ ".rb": "ruby",
26+ ".php": "php",
27+ ".rs": "rust",
28+ ".swift": "swift",
29+ ".kt": "kotlin",
30+ ".scala": "scala",
31+ ".sh": "bash",
32+ ".bash": "bash",
33+ ".zsh": "zsh",
34+ ".fish": "fish",
35+ ".ps1": "powershell",
36+ ".r": "r",
37+ ".sql": "sql",
38+ ".html": "html",
39+ ".htm": "html",
40+ ".xml": "xml",
41+ ".css": "css",
42+ ".scss": "scss",
43+ ".sass": "sass",
44+ ".less": "less",
45+ ".json": "json",
46+ ".yaml": "yaml",
47+ ".yml": "yaml",
48+ ".toml": "toml",
49+ ".ini": "ini",
50+ ".conf": "nginx",
51+ ".md": "markdown",
52+ ".markdown": "markdown",
53+ ".tex": "tex",
54+ ".vim": "vim",
55+ ".lua": "lua",
56+ ".perl": "perl",
57+ ".pl": "perl",
58+ ".dockerfile": "docker",
59+ ".proto": "protobuf",
60+ }
61+
62+ ext := strings.ToLower(filepath.Ext(path))
63+ if lang, ok := languageMap[ext]; ok {
64+ return lang
65+ }
66+
67+ // Check for specific filenames
68+ base := strings.ToLower(filepath.Base(path))
69+ switch base {
70+ case "dockerfile":
71+ return "docker"
72+ case "makefile":
73+ return "make"
74+ case "gemfile":
75+ return "ruby"
76+ case "rakefile":
77+ return "ruby"
78+ }
79+
80+ return "text" // Default fallback
81+}
internal/mcptools/open.go+0−75
@@ -132,78 +132,3 @@ func extractRange(lines []string, full string, start, end int) (string, int, err
132132 }
133133 return strings.Join(lines[start-1:end], "\n"), start, nil
134134 }
135-
136-// DetectLanguage returns the Chroma language identifier based on file extension.
137-func DetectLanguage(path string) string {
138- // Map common extensions to Chroma language identifiers
139- languageMap := map[string]string{
140- ".go": "go",
141- ".py": "python",
142- ".js": "javascript",
143- ".ts": "typescript",
144- ".jsx": "jsx",
145- ".tsx": "tsx",
146- ".java": "java",
147- ".c": "c",
148- ".cpp": "cpp",
149- ".cc": "cpp",
150- ".h": "c",
151- ".hpp": "cpp",
152- ".cs": "csharp",
153- ".rb": "ruby",
154- ".php": "php",
155- ".rs": "rust",
156- ".swift": "swift",
157- ".kt": "kotlin",
158- ".scala": "scala",
159- ".sh": "bash",
160- ".bash": "bash",
161- ".zsh": "zsh",
162- ".fish": "fish",
163- ".ps1": "powershell",
164- ".r": "r",
165- ".sql": "sql",
166- ".html": "html",
167- ".htm": "html",
168- ".xml": "xml",
169- ".css": "css",
170- ".scss": "scss",
171- ".sass": "sass",
172- ".less": "less",
173- ".json": "json",
174- ".yaml": "yaml",
175- ".yml": "yaml",
176- ".toml": "toml",
177- ".ini": "ini",
178- ".conf": "nginx",
179- ".md": "markdown",
180- ".markdown": "markdown",
181- ".tex": "tex",
182- ".vim": "vim",
183- ".lua": "lua",
184- ".perl": "perl",
185- ".pl": "perl",
186- ".dockerfile": "docker",
187- ".proto": "protobuf",
188- }
189-
190- ext := strings.ToLower(filepath.Ext(path))
191- if lang, ok := languageMap[ext]; ok {
192- return lang
193- }
194-
195- // Check for specific filenames
196- base := strings.ToLower(filepath.Base(path))
197- switch base {
198- case "dockerfile":
199- return "docker"
200- case "makefile":
201- return "make"
202- case "gemfile":
203- return "ruby"
204- case "rakefile":
205- return "ruby"
206- }
207-
208- return "text" // Default fallback
209-}
internal/tui/editor/editor.go+3−2
@@ -11,6 +11,7 @@ import (
1111 "charm.land/bubbles/v2/cursor"
1212 tea "charm.land/bubbletea/v2"
1313 "charm.land/lipgloss/v2"
14+ "github.com/xonecas/symb/internal/highlight"
1415 )
1516
1617 // ---------------------------------------------------------------------------
@@ -541,7 +542,7 @@ func (m *Model) bufferColToExpandedCol(bufRow, bufCol int) int {
541542 // theme background, falls back to BgColor.
542543 func (m *Model) bgForRender() lipgloss.Style {
543544 if m.Language != "" && m.SyntaxTheme != "" {
544- if hex := themeBg(m.SyntaxTheme); hex != "" {
545+ if hex := highlight.ThemeBg(m.SyntaxTheme); hex != "" {
545546 return lipgloss.NewStyle().Background(lipgloss.Color(hex))
546547 }
547548 }
@@ -551,7 +552,7 @@ func (m *Model) bgForRender() lipgloss.Style {
551552 // bgHexForHighlight returns the bg hex string for syntax highlighting.
552553 func (m *Model) bgHexForHighlight() string {
553554 if m.Language != "" && m.SyntaxTheme != "" {
554- if hex := themeBg(m.SyntaxTheme); hex != "" {
555+ if hex := highlight.ThemeBg(m.SyntaxTheme); hex != "" {
555556 return hex
556557 }
557558 }
internal/tui/editor/view.go+2−1
@@ -6,6 +6,7 @@ import (
66
77 "charm.land/lipgloss/v2"
88 "github.com/charmbracelet/x/ansi"
9+ "github.com/xonecas/symb/internal/highlight"
910 )
1011
1112 // ---------------------------------------------------------------------------
@@ -98,7 +99,7 @@ func (m Model) buildVisualRows(tw int) []visualRow {
9899
99100 var fullHL string
100101 if hasSyntax {
101- fullHL = cachedHighlight(lineStr, m.Language, m.SyntaxTheme, m.bgHexForHighlight())
102+ fullHL = highlight.CachedHighlight(lineStr, m.Language, m.SyntaxTheme, m.bgHexForHighlight())
102103 }
103104
104105 firstSub := 0
internal/tui/mouse.go+3−3
@@ -9,7 +9,7 @@ import (
99
1010 tea "charm.land/bubbletea/v2"
1111 "github.com/charmbracelet/x/ansi"
12- "github.com/xonecas/symb/internal/mcptools"
12+ "github.com/xonecas/symb/internal/highlight"
1313 )
1414
1515 // ---------------------------------------------------------------------------
@@ -270,7 +270,7 @@ func (m *Model) handleConvClick(wrappedLine int) tea.Cmd {
270270 absPath, _ := filepath.Abs(entry.filePath)
271271 if content, err := os.ReadFile(entry.filePath); err == nil {
272272 m.editor.SetValue(string(content))
273- m.editor.Language = mcptools.DetectLanguage(entry.filePath)
273+ m.editor.Language = highlight.DetectLanguage(entry.filePath)
274274 m.editor.SetGutterMarkers(GitFileMarkers(m.ctx, entry.filePath))
275275 m.editor.DiagnosticLines = nil
276276 m.editorFilePath = absPath
@@ -331,7 +331,7 @@ func (m *Model) tryOpenFilePath(text string) tea.Cmd {
331331 return nil
332332 }
333333
334- language := mcptools.DetectLanguage(path)
334+ language := highlight.DetectLanguage(path)
335335 m.editor.SetValue(string(content))
336336 m.editor.Language = language
337337 m.editor.SetGutterMarkers(GitFileMarkers(m.ctx, path))