Help us shape the future of Go! Take the 2026 Go Developer Survey

session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package session persists every hmm run as a JSONL file in weft's message wire format: line 1 is a session header, then one weft Message per line, then a final usage line. Resume feeds the stored messages back through weft.Messages; dangling tool calls from a crashed run are repaired by weft.Repair.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSessions = errors.New("hmm: no saved sessions")

ErrNoSessions is returned by Newest when the store is empty.

Functions

func HumanID

func HumanID() string

HumanID returns a session id like "amber-moth-482" — the run id and the session file name, chosen to be typed back for --resume.

Types

type Header struct {
	Type     string    `json:"type"` // "session"
	ID       string    `json:"id"`
	Provider string    `json:"provider"`
	Model    string    `json:"model"`
	Created  time.Time `json:"created"`
	Cwd      string    `json:"cwd"`
}

Header is line 1 of a session file.

type Store

type Store struct {
	Dir string
}

Store writes and reads session files under Dir. The zero value is not usable; use New.

func New

func New() (Store, error)

New returns the store rooted at $HMM_HOME/sessions (legacy $BOBINA_HOME), defaulting to ~/.local/share/hmm/sessions — falling back to the pre-rename ~/.local/share/bobina tree when only that exists, so old sessions stay readable.

func (Store) Create

func (s Store) Create(h Header) (*Writer, error)

Create opens <id>.jsonl and writes the header line. Creation is exclusive: a colliding id is an error, never a truncate of the session already living under that name.

func (Store) Newest

func (s Store) Newest(cwd string) (string, error)

Newest returns the id of the most recently modified session file, preferring one whose recorded cwd matches cwd — with several terminals sharing the store, `hmm -c` continues the last chat from this directory, not the last chat anywhere. No match falls back to the global newest.

func (Store) Read

func (s Store) Read(idOrPath string) (Header, []weft.Message, error)

Read loads a session by id, by <id>.jsonl, by path, or by a unique id prefix. An incomplete trailing line (a crashed run mid-write: the file does not end in a newline) is dropped — weft.Repair fills the gap when the transcript is fed back. Corrupt JSON mid-file is an error. The usage line is not returned.

type Usage

type Usage struct {
	Type         string `json:"type"` // "usage"
	InputTokens  int64  `json:"input_tokens"`
	OutputTokens int64  `json:"output_tokens"`
	Steps        int    `json:"steps"`
	StopReason   string `json:"stop_reason,omitempty"`
	Error        string `json:"error,omitempty"`
}

Usage is the final line of a session file. Error is set when the run failed; the messages above it are the partial transcript.

type Writer

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

Writer appends to one session file. Every line is flushed as it is written, so a crash leaves at most an incomplete trailing line — which Read drops.

func (*Writer) Append

func (w *Writer) Append(msgs ...weft.Message) error

Append writes msgs, one message per line, flushing after each.

func (*Writer) Finalize

func (w *Writer) Finalize(u Usage) error

Finalize writes the usage line and closes the file. A nil *Writer is a no-op, so callers can defer it on every path.

Jump to

Keyboard shortcuts

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