mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-15 12:15:16 +00:00
fix: correct context pruning order and vector alignment
- Prune context BEFORE processing (LSTM forget gate pattern) so LLM only sees relevant context, instead of pruning after the fact - Fix ensureTrained() to recompute all event vectors after retraining vectorizer, fixing feature-space mismatch between stored vectors and query vector that made relevance scoring effectively random - Add read lock to knowledge BuildTree() (data race fix) - Log writeIndex() errors instead of discarding them - Fix TOCTOU race in document ContextToDoc() dedup - Fix healthcheck timing (measure elapsed before cleanup) - Refactor waiter CLI into separate files (state, conn, config, editor, history, builtin) for maintainability - Add CLI plugin API key authentication
This commit is contained in:
58
cmd/waiter/history.go
Normal file
58
cmd/waiter/history.go
Normal file
@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type History struct {
|
||||
path string
|
||||
lines []string
|
||||
max int
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func newHistory(path string, max int) History {
|
||||
return History{path: path, max: max}
|
||||
}
|
||||
|
||||
func (h *History) load() {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
data, err := os.ReadFile(h.path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
h.lines = strings.Split(strings.TrimSpace(string(data)), "\n")
|
||||
if len(h.lines) > h.max {
|
||||
h.lines = h.lines[len(h.lines)-h.max:]
|
||||
}
|
||||
}
|
||||
|
||||
func (h *History) save() {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
data := strings.Join(h.lines, "\n") + "\n"
|
||||
os.WriteFile(h.path, []byte(data), 0644)
|
||||
}
|
||||
|
||||
func (h *History) add(line string) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
if len(h.lines) > 0 && h.lines[len(h.lines)-1] == line {
|
||||
return
|
||||
}
|
||||
h.lines = append(h.lines, line)
|
||||
if len(h.lines) > h.max {
|
||||
h.lines = h.lines[len(h.lines)-h.max:]
|
||||
}
|
||||
}
|
||||
|
||||
func (h *History) all() []string {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
r := make([]string, len(h.lines))
|
||||
copy(r, h.lines)
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user