- internal/llama/template.go: ChatML/Llama3 template engine with stop tokens - internal/agent/reasoning.go: parse <think>/<reasoning> tags from LLM output - companion/promptbuilder.go: output structured BuildResult, add date/time context - agent/agent.go: wire templates + reasoning split into message loop - storage: add reasoning TEXT column to messages table + migration - channel/tui.go: collapsible reasoning (tab toggle), mouse scroll, polished dimmed style - config: CHAT_TEMPLATE env var (chatml|llama3|none) - plan.md: mark Phase 2 complete, add themes TODO
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"database/sql"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
type DB struct {
|
|
*sql.DB
|
|
}
|
|
|
|
func Open(path string) (*DB, error) {
|
|
dir := filepath.Dir(path)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return nil, err
|
|
}
|
|
db, err := sql.Open("sqlite", path+"?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Ping(); err != nil {
|
|
return nil, err
|
|
}
|
|
return &DB{db}, nil
|
|
}
|
|
|
|
func (db *DB) Migrate() error {
|
|
for _, m := range migrations {
|
|
err := db.Exec(m)
|
|
if err != nil && m == addReasoningColumn {
|
|
// may already exist on fresh DBs
|
|
continue
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (db *DB) Exec(query string, args ...interface{}) error {
|
|
_, err := db.DB.Exec(query, args...)
|
|
return err
|
|
}
|
|
|
|
func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error) {
|
|
return db.DB.Query(query, args...)
|
|
}
|
|
|
|
func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row {
|
|
return db.DB.QueryRow(query, args...)
|
|
}
|
|
|
|
func (db *DB) Close() error {
|
|
return db.DB.Close()
|
|
}
|