MCPcopy Index your code
hub / github.com/codehamr/codehamr / loadPromptHistory

Function loadPromptHistory

internal/tui/history_store.go:34–53  ·  view source on GitHub ↗

loadPromptHistory returns every saved prompt oldest-first, matching the in-memory append order so historyUp/Down walk the same direction for typed and on-disk entries. A missing file is first-run, not an error.

(dir string)

Source from the content-addressed store, hash-verified

32// in-memory append order so historyUp/Down walk the same direction for
33// typed and on-disk entries. A missing file is first-run, not an error.
34func loadPromptHistory(dir string) []promptEntry {
35 f, err := os.Open(historyPath(dir))
36 if err != nil {
37 return nil
38 }
39 defer f.Close()
40 var out []promptEntry
41 sc := bufio.NewScanner(f)
42 // A prompt may carry a pasted log of tens of KB; raise the per-line cap
43 // past Scanner's 64KB default so we don't drop a long entry's tail.
44 sc.Buffer(make([]byte, 64*1024), historyScannerMax)
45 for sc.Scan() {
46 v, err := strconv.Unquote(sc.Text())
47 if err != nil {
48 continue
49 }
50 out = append(out, promptEntry{display: v})
51 }
52 return out
53}
54
55// appendPromptHistory writes value as one more entry, trimming to
56// historyMaxEntries to bound growth. Empty prompts are skipped so stray ↵

Calls 1

historyPathFunction · 0.85