history

package
v1.66.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package history persists the user's command/message history in an append-only file and provides cursor-based navigation and search over it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type History

type History struct {
	Messages []string
	// contains filtered or unexported fields
}

History is the in-memory view of a persistent message history. The cursor (used by History.Previous and History.Next) stays in [0, len(Messages)], where len(Messages) means "past the most recent entry".

func New

func New(baseDir string) (*History, error)

New loads the history stored under baseDir/.cagent/history. If baseDir is empty, the user's home directory is used.

func (*History) Add

func (h *History) Add(message string) error

Add records a new message. Any prior occurrence of the same message is removed and the new one becomes the most recent entry. The message is scrubbed of secret material via portcullis.Redact before being stored in memory or written to disk so secrets pasted into the prompt never linger in the persistent history.

func (*History) FindNextContains

func (h *History) FindNextContains(query string, from int) (msg string, idx int, ok bool)

FindNextContains searches forward from index from+1 for an entry containing query (case-insensitive). An empty query matches any entry. Pass -1 to start from the oldest entry.

func (*History) FindPrevContains

func (h *History) FindPrevContains(query string, from int) (msg string, idx int, ok bool)

FindPrevContains searches backward from index from-1 for an entry containing query (case-insensitive). An empty query matches any entry. Pass len(Messages) to start from the most recent entry.

func (*History) LatestMatch

func (h *History) LatestMatch(prefix string) string

LatestMatch returns the most recent entry that strictly extends prefix, or an empty string when none does.

func (*History) Next

func (h *History) Next() string

Next moves the cursor one step toward newer entries and returns the entry under it. Past the most recent entry, returns an empty string.

func (*History) Previous

func (h *History) Previous() string

Previous moves the cursor one step toward older entries and returns the entry under it. At the oldest entry, the cursor stays put.

func (*History) SetCurrent

func (h *History) SetCurrent(i int)

SetCurrent positions the cursor at index i, clamped to [0, len(Messages)]. Keeping the cursor in this range guarantees that subsequent Previous and Next calls never index out of bounds.

Jump to

Keyboard shortcuts

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