session

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package session writes session transcripts to disk on exit.

Every run that has a project .agents/ directory persists a JSON transcript to .agents/sessions/<RFC3339-timestamp>.json containing the chat history and the final usage totals. The schema is versioned so future readers can evolve safely.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the on-disk schema version for transcripts.

View Source
const SessionsDirName = "sessions"

SessionsDirName is the subdirectory under .agents/ where transcripts land. Created on demand.

Variables

View Source
var ErrNoProject = errors.New("session: no project directory configured")

ErrNoProject is a sentinel callers can check via errors.Is when they want to distinguish "no project" from a real failure.

Functions

func Save

func Save(agentsDir string, t Transcript) (string, error)

Save writes t to <agentsDir>/sessions/<timestamp>.json atomically. Empty agentsDir is a no-op (no project root → no place to write).

Returns the absolute path of the new file (or "" when skipped).

Types

type Message

type Message struct {
	Role string `json:"role"`
	Text string `json:"text"`
}

Message is one entry in the chat. Role is "user" | "assistant" | "system" | "error".

type Transcript

type Transcript struct {
	Version   int       `json:"version"`
	StartedAt time.Time `json:"started_at"`
	EndedAt   time.Time `json:"ended_at"`
	Model     string    `json:"model"`
	Messages  []Message `json:"messages"`
	Usage     Usage     `json:"usage"`
}

Transcript captures one session for archival.

type Usage

type Usage struct {
	Turns        int     `json:"turns"`
	InputTokens  int     `json:"input_tokens"`
	OutputTokens int     `json:"output_tokens"`
	CostUSD      float64 `json:"cost_usd"`
}

Usage mirrors usage.Totals, written by value so the transcript doesn't need to import the usage package.

Jump to

Keyboard shortcuts

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