session

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package session implements append-only JSONL rollouts plus parent-pointer tree reconstruction for bee sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTree

func BuildTree(msgs []types.Message) *types.MessageNode

BuildTree reconstructs the parent-pointer tree from a flat message slice. Returns the root node (first message with empty ParentID, or with a parent not present in the slice). If multiple roots exist, the first-seen wins and orphan subtrees are dropped — callers should ensure input is from one session. Returns nil if msgs is empty.

func FirstUserText

func FirstUserText(id string) (string, error)

FirstUserText returns the first user-role text block in a session, scanning at most maxScanLines lines. Empty if the session has no user text yet.

func LinearPath

func LinearPath(root *types.MessageNode, leafID string) []*types.MessageNode

LinearPath walks from leafID up to root, returning the chain in root→leaf order. Returns nil if leafID isn't reachable.

func List

func List() ([]types.Session, error)

List enumerates known sessions by scanning the sessions dir. Each session's metadata is derived from its first message (timestamp = session created, id from filename). Provider/model/cwd aren't in Message; downstream code can enrich Session as it pleases — we fill what we can.

func Path

func Path(id string) (string, error)

Path returns the JSONL file path for a session id.

func Read

func Read(id string) ([]types.Message, error)

Read decodes all messages in a session file, in append order.

func ReadResume

func ReadResume(id string) ([]types.Message, error)

ReadResume decodes a session like Read but collapses it at the last compaction checkpoint: the checkpoint's summary stands in for everything before PreserveFrom, so a resumed session sees the same shortened history the live session had instead of the full raw log. Falls back to the raw read when no checkpoint exists or PreserveFrom can't be located.

func SessionsDir

func SessionsDir() (string, error)

SessionsDir returns the directory holding session JSONL files. Override via BEE_SESSIONS_DIR for tests / alt installs.

Types

type Rollout

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

Rollout is an append-only JSONL writer for one session. Single open handle, sync-on-append. Not safe for cross-process use; callers are expected to own the session.

func Clone

func Clone(srcID string) (*Rollout, error)

Clone copies an entire session into a new rollout.

func Fork

func Fork(srcID, fromMsgID string) (*Rollout, error)

Fork creates a new session rollout containing all messages up to and including fromMsgID. If fromMsgID is empty the entire source session is copied (Clone). The new rollout is returned open; caller is responsible for Close.

func Open

func Open(id string) (*Rollout, error)

Open opens (or creates) the rollout file for session id.

func (*Rollout) Append

func (r *Rollout) Append(ctx context.Context, msg types.Message) error

Append writes one message as a single JSON line, then fsyncs. Context is honored only for cancellation before the write begins; stdlib file I/O is uninterruptible mid-call.

func (*Rollout) Close

func (r *Rollout) Close() error

Close releases the file handle.

func (*Rollout) FilePath

func (r *Rollout) FilePath() string

Path returns the on-disk file path.

func (*Rollout) ID

func (r *Rollout) ID() string

ID returns the session id this rollout writes.

Jump to

Keyboard shortcuts

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