-
-
Notifications
You must be signed in to change notification settings - Fork 0
Prompt History
Eshan Roy edited this page Jun 16, 2026
·
3 revisions
M31A maintains a frecent (frequent + recent) prompt history that powers autocomplete suggestions in the REPL. History is persisted as JSON and survives across sessions.
Source: pkg/history/history.go
type FrecentHistory struct {
mu sync.RWMutex
entries []FrecentEntry
filePath string
}
type FrecentEntry struct {
Text string `json:"text"`
Score float64 `json:"score"`
LastUsed time.Time `json:"last_used"`
UseCount int `json:"use_count"`
}Each entry's score combines recency and frequency:
func (fh *FrecentHistory) computeScore(e FrecentEntry) float64 {
ageHours := time.Since(e.LastUsed).Hours()
recency := 1.0 / (1.0 + ageHours/24.0) // exponential decay over 24h
return recency * float64(e.UseCount) * 10 + recency
}- Recency: Exponential decay with 24-hour half-life
- Frequency: Use count multiplied by recency factor
- Entries are sorted by score (highest first)
| Method | Description |
|---|---|
Upsert(text) |
Add or update entry, increment use count, save to disk |
Search(query, limit) |
Substring match, sorted by most recently used |
Save() |
Persist to disk as JSON |
- Trim whitespace
- If text exists: increment
UseCount, updateLastUsed, recompute score - If new: create entry with
UseCount=1 - Cap at 500 entries (trim lowest-scored)
- Persist to disk immediately
- Case-insensitive substring match
- Sort results by
LastUsed(most recent first) - Limit results if requested
History is stored as JSON in the session directory:
- File permissions:
0600(owner read/write only) - Directory permissions:
0700 - On corrupt file: log warning and start with empty history
- Save is triggered on every upsert and on application shutdown
[ui]
frecent_history_size = 100 # Max entries in frecent historyThe REPL model uses FrecentHistory for:
- Autocomplete suggestions as the user types
- Quick access to recent prompts via Up arrow
- Prompt history browser (
/prompt-historycommand)