session

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 11 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

Index

Constants

View Source
const (
	Ext = ".jsonl"

	// Schema version written into new logs
	Version = 1
)

Variables

This section is empty.

Functions

func FindByPrefix

func FindByPrefix(prefix string) (string, error)

Resolves a full or prefix session ID to a log path, or an error if missing/ambiguous

func NewID

func NewID() (string, error)

func Path

func Path(id string) string

Returns the log file of a session in the current project

Types

type Entry

type Entry struct {
	Role    string    `json:"role"`
	Content string    `json:"content"`
	At      time.Time `json:"at,omitzero"`
}

type State

type State struct {
	ID          string
	Version     int
	ProjectPath string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	Model       string
	Mode        string

	// Rendered transcript, in display order
	Entries []Entry
	// What the user typed, in submission order
	InputHistory []string
	// Agent conversation, one raw JSON message each
	Messages []json.RawMessage
	// Whether the log ended with a clean shutdown
	Complete bool
}

func Load

func Load(path string) (*State, error)

Folds a session log back into a State, skipping torn lines

type Writer

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

Appends a session's records to its log, buffering until armed

func NewWriter

func NewWriter(s *State) *Writer

Prepares a log; no file is touched until armed and flushed

func Reopen

func Reopen(path string) *Writer

Continues an existing log; armed since the session is already worth keeping

func (*Writer) AppendEntry

func (w *Writer) AppendEntry(role, content string, at time.Time)

Queues a transcript line; zero time means now

func (*Writer) AppendInput

func (w *Writer) AppendInput(text string)

Queues a user submission

func (*Writer) AppendMessage

func (w *Writer) AppendMessage(msg json.RawMessage)

Queues an agent message, untimed since it is collected at flush

func (*Writer) AppendReset

func (w *Writer) AppendReset()

Queues a marker that discards earlier agent messages

func (*Writer) Arm

func (w *Writer) Arm()

Lets the next Flush create the log file

func (*Writer) Armed

func (w *Writer) Armed() bool

Reports whether Flush will write

func (*Writer) Close

func (w *Writer) Close(mode string) error

Flushes, writes the end record and closes; no-op if never armed

func (*Writer) Created

func (w *Writer) Created() bool

Reports whether the log file exists yet

func (*Writer) Flush

func (w *Writer) Flush() error

Appends the queued records once armed

func (*Writer) Path

func (w *Writer) Path() string

Returns the log file

Jump to

Keyboard shortcuts

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