history

package
v1.5.21 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package history persists the global, append-only prompt history shared by golder's interactive front-ends (the TUI for now). It mirrors Codex's message-history store: one JSON object per line in $GOLDER_HOME/history.jsonl, appended with a single write so concurrent processes never interleave partial lines, capped by size so the file cannot grow without bound. The front-end reads the newest entries once (lazily, on first use) and keeps them in memory for ↑/↓ browsing and Ctrl+R search across sessions.

Index

Constants

View Source
const FileName = "history.jsonl"

FileName is the history file inside the golder home directory.

View Source
const MaxEntries = 500

MaxEntries bounds what Load returns: the newest N entries. The on-disk file can hold more (up to maxBytes); the reader only ever holds this window.

Variables

This section is empty.

Functions

func Append

func Append(path string, e Entry) error

Append adds one entry to the history file at path, creating it (and its parent directory) when needed. The record is marshaled first and written to an O_APPEND descriptor in one Write, so concurrent appenders do not interleave partial lines; the file is mode 0600. When the file exceeds maxBytes it is rewritten to keep the newest lines (trimRatio of the cap). Appending to a path whose directory cannot be resolved fails.

func WriteAll

func WriteAll(path string, entries []Entry) error

WriteAll replaces the history file with entries (oldest first), creating the parent directory as needed. It writes through a temp file and an atomic rename at mode 0600, so a concurrent reader never sees a half-written file. It is the bulk-write counterpart to Append, used by the one-time backfill that seeds the file from existing sessions.

Types

type Entry

type Entry struct {
	TS        int64  `json:"ts"`
	SessionID string `json:"session_id,omitempty"`
	Cwd       string `json:"cwd,omitempty"`
	Text      string `json:"text"`
}

Entry is one persisted prompt-history record. Text is the fully expanded prompt as submitted (paste placeholders resolved), so recalling and resubmitting it is faithful.

func Load

func Load(path string, max int) ([]Entry, error)

Load returns up to max of the newest entries in chronological (oldest-first) order. A missing file is an empty history, not an error; malformed lines are skipped (best-effort read — a corrupted line must not hide the rest).

Jump to

Keyboard shortcuts

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