xonecas.io
62159
Sy

symb / commit 29dd107

feat: session storage

xonecas2026-02-14 29dd10795a8e102b278c441b4f136d6e6150fede parent 3230270

9 files changed

README.md+3−5
@@ -19,6 +19,7 @@ Symb pairs you with an LLM, providing an agentic UI with tools the LLM can use t
1919 ## Features
2020
2121 - **Dual-pane TUI**: Code viewer on one side, agent conversation on the other
22+- **Mouse support**: Click on conversation log to view files, changes, and tool call outputs in the code pane in full.
2223 - **Syntax highlighting**: Via Chroma for Go and other languages
2324 - **Clean aesthetic**: Dark grayscale with minimal distractions
2425 - **ELM architecture**: Built with BubbleTea for solid state management
@@ -28,6 +29,7 @@ Symb pairs you with an LLM, providing an agentic UI with tools the LLM can use t
2829 - **Git integration**: Diff viewing and change tracking for version control awareness
2930 - **LSP diagnostics**: Closed-loop edit validation with language server feedback
3031 - **Deterministic schemas**: KV-cache optimized tool definitions for reproducible LLM behavior
32+- **Session storage**: Sessions saved to app data in sqlite file. Session management comming soon (--resume, --list, --session <ID>)
3133
3234 ## Quick Start
3335
@@ -37,9 +39,6 @@ make build
3739
3840 # Run
3941 make run
40-
41-# Development mode
42-make dev
4342 ```
4443
4544 ## Configuration
@@ -71,7 +70,6 @@ API keys are stored separately in `~/.config/symb/credentials.json`:
7170
7271 See `docs/DESIGN.md` for architecture and design philosophy.
7372
74-
7573 ---
7674
7775 ## Notes from Claude (Opus 4.6, first full-model test)
@@ -88,4 +86,4 @@ The Symb harness is genuinely well-designed from an LLM's perspective. A few obs
8886 - No shell execution yet means I can't run `make build` to verify my changes compile. I have to trust my edits are correct. LSP diagnostics will help close this gap.
8987 - The 2-char hash has a small collision space (256 values), but for typical file sizes it's fine — and the line number + hash combo makes collisions practically irrelevant.
9088
91-Overall: this is one of the more thoughtful agent harnesses I've worked in. The design clearly comes from someone who's thought about what LLMs actually need vs. what looks impressive in a demo.
89+Overall: this is one of the more thoughtful agent harnesses I've worked in. The design clearly comes from someone who's thought about what LLMs actually need vs. what looks impressive in a demo.
cmd/symb/main.go+16−1
@@ -2,6 +2,8 @@ package main
22
33 import (
44 "context"
5+ "crypto/rand"
6+ "encoding/hex"
57 "fmt"
68 "os"
79 "path/filepath"
@@ -60,8 +62,15 @@ func main() {
6062 tools = []mcp.Tool{}
6163 }
6264
65+ sessionID := newSessionID()
66+ if webCache != nil {
67+ if err := webCache.CreateSession(sessionID); err != nil {
68+ fmt.Printf("Warning: failed to create session: %v\n", err)
69+ }
70+ }
71+
6372 p := tea.NewProgram(
64- tui.New(prov, proxy, tools, providerCfg.Model),
73+ tui.New(prov, proxy, tools, providerCfg.Model, webCache, sessionID),
6574 tea.WithFilter(tui.MouseEventFilter),
6675 )
6776 lspManager.SetCallback(func(absPath string, lines map[int]int) {
@@ -152,6 +161,12 @@ func openWebCache(cfg *config.Config) *store.Cache {
152161 return cache
153162 }
154163
164+func newSessionID() string {
165+ b := make([]byte, 16)
166+ rand.Read(b) //nolint:errcheck
167+ return hex.EncodeToString(b)
168+}
169+
155170 func setupFileLogging() error {
156171 zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
157172
docs/DESIGN.md+7−8
@@ -83,14 +83,18 @@ Retry-After parsing.
8383 - Show closed loop feedback on mutations done by the llm.
8484 - Start with diagnostics (show errors/warnings in the number line, a error line has a red color number, warnings yellow).
8585
86-## Features waiting implementation for current version:
87-
8886 ### Basic Session storage
8987
9088 - table for conversation messages
9189 - each message includes all tool calls
9290 - 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**
91+
92+## Features waiting implementation for current version:
93+
94+### Tree-Sitter Context
95+
96+Parse project with tree-sitter for structural awareness. Feed relevant
97+symbols/scope to LLM as auto-context instead of whole files.
9498
9599 ### Undo!
96100
@@ -107,11 +111,6 @@ Needs an undo.
107111
108112 https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
109113
110-### Tree-Sitter Context
111-
112-Parse project with tree-sitter for structural awareness. Feed relevant
113-symbols/scope to LLM as auto-context instead of whole files.
114-
115114 ### Conversation log improvements:
116115
117116 Update hover iteraction on tool responses for ux and tool call tui output.
internal/store/session.go+120−0
@@ -0,0 +1,120 @@
1+package store
2+
3+import (
4+ "encoding/json"
5+ "time"
6+
7+ "github.com/rs/zerolog/log"
8+)
9+
10+// Session represents a conversation session.
11+type Session struct {
12+ ID string
13+ Title string
14+ Created time.Time
15+ Updated time.Time
16+}
17+
18+// SessionMessage is a persisted chat message.
19+type SessionMessage struct {
20+ Role string
21+ Content string
22+ Reasoning string
23+ ToolCalls json.RawMessage // JSON array
24+ ToolCallID string
25+ CreatedAt time.Time
26+}
27+
28+// CreateSession inserts a new session and returns its ID.
29+func (c *Cache) CreateSession(id string) error {
30+ if c == nil {
31+ return nil
32+ }
33+ c.mu.Lock()
34+ defer c.mu.Unlock()
35+
36+ now := time.Now().Unix()
37+ _, err := c.db.Exec(
38+ "INSERT INTO sessions (id, title, created, updated) VALUES (?, '', ?, ?)",
39+ id, now, now,
40+ )
41+ if err != nil {
42+ log.Warn().Err(err).Str("id", id).Msg("failed to create session")
43+ }
44+ return err
45+}
46+
47+// SaveMessage queues a message for async persistence. Non-blocking.
48+func (c *Cache) SaveMessage(sessionID string, msg SessionMessage) {
49+ if c == nil {
50+ return
51+ }
52+ select {
53+ case c.saveCh <- saveReq{sessionID: sessionID, msg: msg}:
54+ default:
55+ log.Warn().Str("session", sessionID).Msg("save channel full, dropping message")
56+ }
57+}
58+
59+// saveLoop drains saveCh and writes messages to the DB.
60+func (c *Cache) saveLoop() {
61+ defer close(c.done)
62+ for req := range c.saveCh {
63+ c.writeMessage(req.sessionID, req.msg)
64+ }
65+}
66+
67+// writeMessage performs the actual DB insert for a message.
68+func (c *Cache) writeMessage(sessionID string, msg SessionMessage) {
69+ c.mu.Lock()
70+ defer c.mu.Unlock()
71+
72+ tc := msg.ToolCalls
73+ if tc == nil {
74+ tc = json.RawMessage("[]")
75+ }
76+
77+ _, err := c.db.Exec(
78+ `INSERT INTO messages (session_id, role, content, reasoning, tool_calls, tool_call_id, created)
79+ VALUES (?, ?, ?, ?, ?, ?, ?)`,
80+ sessionID, msg.Role, msg.Content, msg.Reasoning, string(tc), msg.ToolCallID, msg.CreatedAt.Unix(),
81+ )
82+ if err != nil {
83+ log.Warn().Err(err).Str("session", sessionID).Msg("failed to save message")
84+ }
85+
86+ // Touch session updated time.
87+ c.db.Exec("UPDATE sessions SET updated = ? WHERE id = ?", time.Now().Unix(), sessionID) //nolint:errcheck
88+}
89+
90+// LoadMessages returns all messages for a session, ordered by ID.
91+func (c *Cache) LoadMessages(sessionID string) ([]SessionMessage, error) {
92+ if c == nil {
93+ return nil, nil
94+ }
95+ c.mu.Lock()
96+ defer c.mu.Unlock()
97+
98+ rows, err := c.db.Query(
99+ `SELECT role, content, reasoning, tool_calls, tool_call_id, created
100+ FROM messages WHERE session_id = ? ORDER BY id`, sessionID,
101+ )
102+ if err != nil {
103+ return nil, err
104+ }
105+ defer rows.Close()
106+
107+ var msgs []SessionMessage
108+ for rows.Next() {
109+ var m SessionMessage
110+ var tc string
111+ var created int64
112+ if err := rows.Scan(&m.Role, &m.Content, &m.Reasoning, &tc, &m.ToolCallID, &created); err != nil {
113+ continue
114+ }
115+ m.ToolCalls = json.RawMessage(tc)
116+ m.CreatedAt = time.Unix(created, 0)
117+ msgs = append(msgs, m)
118+ }
119+ return msgs, rows.Err()
120+}
internal/store/store.go+43−6
@@ -27,13 +27,41 @@ CREATE TABLE IF NOT EXISTS search_cache (
2727
2828 CREATE INDEX IF NOT EXISTS idx_fetch_created ON fetch_cache(created);
2929 CREATE INDEX IF NOT EXISTS idx_search_created ON search_cache(created);
30+
31+CREATE TABLE IF NOT EXISTS sessions (
32+ id TEXT PRIMARY KEY,
33+ title TEXT NOT NULL DEFAULT '',
34+ created INTEGER NOT NULL,
35+ updated INTEGER NOT NULL
36+);
37+
38+CREATE TABLE IF NOT EXISTS messages (
39+ id INTEGER PRIMARY KEY AUTOINCREMENT,
40+ session_id TEXT NOT NULL REFERENCES sessions(id),
41+ role TEXT NOT NULL,
42+ content TEXT NOT NULL DEFAULT '',
43+ reasoning TEXT NOT NULL DEFAULT '',
44+ tool_calls TEXT NOT NULL DEFAULT '[]',
45+ tool_call_id TEXT NOT NULL DEFAULT '',
46+ created INTEGER NOT NULL
47+);
48+
49+CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id, id);
3050 `
3151
32-// Cache is a SQLite-backed cache for web results.
52+// saveReq is an internal message sent to the background save goroutine.
53+type saveReq struct {
54+ sessionID string
55+ msg SessionMessage
56+}
57+
58+// Cache is a SQLite-backed cache for web results and session storage.
3359 type Cache struct {
34- mu sync.Mutex
35- db *sql.DB
36- ttl time.Duration
60+ mu sync.Mutex
61+ db *sql.DB
62+ ttl time.Duration
63+ saveCh chan saveReq // buffered channel for async message saves
64+ done chan struct{} // closed when background goroutine exits
3765 }
3866
3967 // Open creates or opens a cache database at the given path.
@@ -49,6 +77,7 @@ func Open(dbPath string, ttl time.Duration) (*Cache, error) {
4977 "PRAGMA journal_mode = WAL",
5078 "PRAGMA synchronous = NORMAL",
5179 "PRAGMA busy_timeout = 5000",
80+ "PRAGMA foreign_keys = ON",
5281 } {
5382 if _, err := db.Exec(pragma); err != nil {
5483 db.Close()
@@ -67,16 +96,24 @@ func Open(dbPath string, ttl time.Duration) (*Cache, error) {
6796 return nil, fmt.Errorf("create schema: %w", err)
6897 }
6998
70- c := &Cache{db: db, ttl: ttl}
99+ c := &Cache{
100+ db: db,
101+ ttl: ttl,
102+ saveCh: make(chan saveReq, 256),
103+ done: make(chan struct{}),
104+ }
105+ go c.saveLoop()
71106 c.purgeStale()
72107 return c, nil
73108 }
74109
75-// Close closes the database.
110+// Close drains pending saves and closes the database.
76111 func (c *Cache) Close() error {
77112 if c == nil {
78113 return nil
79114 }
115+ close(c.saveCh)
116+ <-c.done
80117 return c.db.Close()
81118 }
82119
internal/tui/golden_test.go+1−1
@@ -26,7 +26,7 @@ func TestLayout(t *testing.T) {
2626
2727 for _, tt := range tests {
2828 t.Run(tt.name, func(t *testing.T) {
29- m := New(nil, nil, nil, "test-model")
29+ m := New(nil, nil, nil, "test-model", nil, "test-session")
3030 updated, _ := m.Update(tea.WindowSizeMsg{Width: tt.width, Height: tt.height})
3131 m = updated.(Model)
3232
internal/tui/messages.go+26−0
@@ -1,12 +1,14 @@
11 package tui
22
33 import (
4+ "encoding/json"
45 "time"
56
67 tea "charm.land/bubbletea/v2"
78 "github.com/xonecas/symb/internal/llm"
89 "github.com/xonecas/symb/internal/mcp"
910 "github.com/xonecas/symb/internal/provider"
11+ "github.com/xonecas/symb/internal/store"
1012 )
1113
1214 // ---------------------------------------------------------------------------
@@ -132,3 +134,27 @@ func (m Model) processLLM() tea.Cmd {
132134 return nil
133135 }
134136 }
137+
138+// messageToStore converts a provider.Message to a store.SessionMessage.
139+func messageToStore(msg provider.Message) store.SessionMessage {
140+ var tc json.RawMessage
141+ if len(msg.ToolCalls) > 0 {
142+ tc, _ = json.Marshal(msg.ToolCalls) //nolint:errcheck
143+ }
144+ return store.SessionMessage{
145+ Role: msg.Role,
146+ Content: msg.Content,
147+ Reasoning: msg.Reasoning,
148+ ToolCalls: tc,
149+ ToolCallID: msg.ToolCallID,
150+ CreatedAt: msg.CreatedAt,
151+ }
152+}
153+
154+// saveMessage persists a message to the session store (no-op if store is nil).
155+func (m *Model) saveMessage(msg provider.Message) {
156+ if m.store == nil {
157+ return
158+ }
159+ m.store.SaveMessage(m.sessionID, messageToStore(msg))
160+}
internal/tui/tui.go+15−2
@@ -13,6 +13,7 @@ import (
1313 "github.com/xonecas/symb/internal/llm"
1414 "github.com/xonecas/symb/internal/mcp"
1515 "github.com/xonecas/symb/internal/provider"
16+ "github.com/xonecas/symb/internal/store"
1617 "github.com/xonecas/symb/internal/tui/editor"
1718 )
1819
@@ -175,6 +176,10 @@ type Model struct {
175176 ctx context.Context
176177 cancel context.CancelFunc
177178
179+ // Session persistence
180+ store *store.Cache
181+ sessionID string
182+
178183 // Conversation
179184 convEntries []convEntry // Conversation entries (not wrapped)
180185 convLines []string // Wrapped visual lines (cache, rebuilt on width change)
@@ -204,7 +209,7 @@ type Model struct {
204209 }
205210
206211 // New creates a new TUI model.
207-func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID string) Model {
212+func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID string, db *store.Cache, sessionID string) Model {
208213 sty := DefaultStyles()
209214 cursorStyle := lipgloss.NewStyle().Foreground(ColorHighlight)
210215
@@ -244,6 +249,11 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
244249 ctx, cancel := context.WithCancel(context.Background())
245250
246251 systemPrompt := llm.BuildSystemPrompt(modelID)
252+ systemMsg := provider.Message{Role: "system", Content: systemPrompt, CreatedAt: time.Now()}
253+
254+ if db != nil {
255+ db.SaveMessage(sessionID, messageToStore(systemMsg))
256+ }
247257
248258 return Model{
249259 spinner: s,
@@ -255,12 +265,15 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
255265 provider: prov,
256266 mcpProxy: proxy,
257267 mcpTools: tools,
258- history: []provider.Message{{Role: "system", Content: systemPrompt, CreatedAt: time.Now()}},
268+ history: []provider.Message{systemMsg},
259269 convEntries: []convEntry{},
260270 updateChan: ch,
261271 ctx: ctx,
262272 cancel: cancel,
263273
274+ store: db,
275+ sessionID: sessionID,
276+
264277 streamEntryStart: -1,
265278 hoverConvLine: -1,
266279 }
internal/tui/update.go+4−3
@@ -138,9 +138,9 @@ func (m *Model) handleKeyPress(msg tea.KeyPressMsg) (Model, tea.Cmd, bool) {
138138 // handleUserMsg records a user message in history and conversation display.
139139 func (m *Model) handleUserMsg(msg llmUserMsg) Model {
140140 now := time.Now()
141- m.history = append(m.history, provider.Message{
142- Role: "user", Content: msg.content, CreatedAt: now,
143- })
141+ userMsg := provider.Message{Role: "user", Content: msg.content, CreatedAt: now}
142+ m.history = append(m.history, userMsg)
143+ m.saveMessage(userMsg)
144144 m.appendText(styledLines(msg.content, m.styles.Text)...)
145145 m.appendText("")
146146 sep := m.makeSeparator("0s", now.Format("15:04:05"))
@@ -172,6 +172,7 @@ func (m Model) handleLLMBatch(batch llmBatchMsg) (tea.Model, tea.Cmd) {
172172
173173 case llmHistoryMsg:
174174 m.history = append(m.history, msg.msg)
175+ m.saveMessage(msg.msg)
175176
176177 case llmAssistantMsg:
177178 needRebuild = m.flushRebuild(needRebuild)