countHistoryLines tallies lines without parsing them: fast path for the trim decision in appendPromptHistory.
(path string)
| 113 | // countHistoryLines tallies lines without parsing them: fast path for the |
| 114 | // trim decision in appendPromptHistory. |
| 115 | func countHistoryLines(path string) (int, error) { |
| 116 | f, err := os.Open(path) |
| 117 | if err != nil { |
| 118 | return 0, err |
| 119 | } |
| 120 | defer f.Close() |
| 121 | sc := bufio.NewScanner(f) |
| 122 | sc.Buffer(make([]byte, 64*1024), historyScannerMax) |
| 123 | n := 0 |
| 124 | for sc.Scan() { |
| 125 | n++ |
| 126 | } |
| 127 | return n, sc.Err() |
| 128 | } |
| 129 | |
| 130 | // clearPromptHistory removes the on-disk file so /clear also wipes recall. |
| 131 | // A missing file is not an error: the empty-history intent already holds. |
no outgoing calls
no test coverage detected