diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-17 11:28:19 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-17 11:28:19 +0200 |
| commit | 6f1c8bf7a36eb7044ed7aad30f84664cbbf0d303 (patch) | |
| tree | dd2ac6e1433177fb59c167a12fa0b4b91132f34a /internal/promptstore | |
| parent | 10562cc510f64d5ac38aeb76f03e18eb76cca40f (diff) | |
Fix bugs, remove duplication, and clean up code quality issues
- Log swallowed JSON unmarshal errors in stats and LSP handlers
- Fix debug log file handle leak in tmuxedit (return closer from initDebugLog)
- Check f.Close() errors on write paths in promptstore and tmuxedit
- Fix cacheGet TOCTOU race by using single write lock
- Fix readInput to use passed stdin reader instead of os.Stdin.Stat()
- Remove 45 'moved to' comment tombstones from lsp/handlers.go
- Deduplicate canonicalProvider wrappers (use llmutils.CanonicalProvider directly)
- Remove SetWindow side effect from stats.TakeSnapshot (pure read now)
- Move duplicated splitLines to textutil.SplitLinesBytes
- Collapse StatusSink.SetGlobal 10 params into GlobalStatus struct
- Simplify LRU touchLocked to in-place delete-and-append
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'internal/promptstore')
| -rw-r--r-- | internal/promptstore/store.go | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/internal/promptstore/store.go b/internal/promptstore/store.go index 1597b36..6cabebd 100644 --- a/internal/promptstore/store.go +++ b/internal/promptstore/store.go @@ -10,6 +10,8 @@ import ( "strings" "sync" "time" + + "codeberg.org/snonux/hexai/internal/textutil" ) // PromptStore defines the interface for prompt storage operations. @@ -182,13 +184,14 @@ func (s *JSONLStore) Create(prompt *Prompt) error { if err != nil { return fmt.Errorf("open user.jsonl: %w", err) } - defer f.Close() + defer func() { _ = f.Close() }() // best-effort on error paths if _, err := f.Write(data); err != nil { return fmt.Errorf("write user.jsonl: %w", err) } - return nil + // Check Close error to catch deferred-write failures (e.g. disk full). + return f.Close() } // Update modifies an existing prompt in user.jsonl. @@ -377,7 +380,7 @@ func (s *JSONLStore) loadPromptsFromFile(filename string) ([]Prompt, error) { } var prompts []Prompt - lines := splitLines(data) + lines := textutil.SplitLinesBytes(data) for i, line := range lines { if len(line) == 0 { continue @@ -416,27 +419,6 @@ func (s *JSONLStore) writePromptsToFile(filename string, prompts []Prompt) error return nil } -// splitLines splits data into lines (handles both \n and \r\n). -// Copied from tmuxedit/history.go pattern. -func splitLines(data []byte) [][]byte { - var lines [][]byte - start := 0 - for i := 0; i < len(data); i++ { - if data[i] == '\n' { - end := i - if end > start && data[end-1] == '\r' { - end-- - } - lines = append(lines, data[start:end]) - start = i + 1 - } - } - if start < len(data) { - lines = append(lines, data[start:]) - } - return lines -} - // backupUserPrompts creates a timestamped backup of user.jsonl before any write operation. // Automatically manages backup retention based on maxBackups setting. func (s *JSONLStore) backupUserPrompts() error { |
