history

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package history is the input-history store: the lines the person typed, kept across sessions so a surface can walk them back with the up arrow.

The file is JSONL at a caller-given path — one line per entry, append-only — for the same reason the session journal is: a crash mid-write costs the last line and nothing before it, and reading it back is a forward scan with no rewrite. A line that does not parse is skipped rather than fatal.

Two properties shape the rest of the package:

  • Capture must never block the input path. Append puts an entry on an in-memory queue and returns; one goroutine drains the queue to disk every flushInterval, so a person typing fast pays a slice append per prompt and the file pays one write per batch. Close drains synchronously.
  • History is a CONVENIENCE, not an archive. The file is capped (see maxEntries) and a write that fails is dropped in silence — the session JSONL is the record of what happened, this is a recall list. Nothing here is worth interrupting a person mid-turn for.

This package is storage only. It renders nothing, knows no key bindings, and imports no surface.

KNOWN LIMITATION: the file is not locked, and a Store caches its contents in memory after the first read. Two codeaf processes on the same path interleave their appends (harmless — every line is independent) but each keeps serving recall from the snapshot it loaded, so neither sees the other's new lines until it is restarted. That is the right trade for a recall list; the fix, if a shared history ever matters, is a stat-and-reload on Recent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Text string    `json:"text"`
	Cwd  string    `json:"cwd"`
	Ts   time.Time `json:"ts"`
}

Entry is one captured input: what was typed, where, and when.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is an open history file. Use New, and Close it when the surface exits.

Two locks, deliberately. queueMu guards the handoff between the input path and the drain goroutine and is never held across I/O, so Append cannot be made to wait on a disk write; mu guards the file and the loaded snapshot. They are taken in that order (queueMu, released, then mu) and never nested.

func New

func New(path string) *Store

New opens a history store at path. Nothing is read or created here: the file is loaded on the first Recent (or the first flush), so a surface that never recalls and never types pays nothing, and a path under a directory that does not exist yet is created on the first write rather than at startup.

func (*Store) Append

func (s *Store) Append(text, cwd string)

Append records one input. It returns immediately — the entry is written by the drain goroutine.

Two entries never reach the file: blank text, and a repeat of the line this store recorded last. Consecutive-identical dedupe is what makes the up-arrow walk useful — a person who runs the same command three times wants one step back through it, not three.

func (*Store) Close

func (s *Store) Close() error

Close stops the drain goroutine and writes whatever it was holding. It is safe to call twice; Appends after it are dropped rather than queued for a goroutine that will never run again.

func (*Store) Recent

func (s *Store) Recent(limit int) []Entry

Recent returns the newest entries first, across every cwd. A limit of zero or less returns all of them.

func (*Store) RecentFor

func (s *Store) RecentFor(cwd string, limit int) []Entry

RecentFor is Recent narrowed to one working directory — the recall list for the project the person is standing in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL