Documentation
¶
Overview ¶
Package session provides the core session model: id, title, created_at, and conversation history. File-based persistence lives in internal/agentapp (SessionStore).
Index ¶
- Variables
- func CtxWithSessionID(ctx context.Context, id string) context.Context
- func EnsureTitleFromFirstUserMessage(s *Session, maxLen int)
- func NewID() string
- func SessionIDFromContext(ctx context.Context) (string, bool)
- type Session
- func (s *Session) AddCompaction(summary string, summarizedCount int)
- func (s *Session) Append(msg llm.Message) error
- func (s *Session) HistoryMessages() []llm.Message
- func (s *Session) Notes() []agent.Note
- func (s *Session) PriorSummary() string
- func (s *Session) SetNotes(notes []agent.Note, iter int)
- func (s *Session) SetTodos(todos []agent.Todo, iter int)
- func (s *Session) Todos() []agent.Todo
- type SessionItem
Constants ¶
This section is empty.
Variables ¶
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is returned when a session file does not exist.
Functions ¶
func CtxWithSessionID ¶
CtxWithSessionID returns a context that carries the given session ID.
func EnsureTitleFromFirstUserMessage ¶
EnsureTitleFromFirstUserMessage sets the session title from the first user message if the title is empty, truncated to maxLen runes. No-op otherwise.
Types ¶
type Session ¶
type Session struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
CreatedAt time.Time `json:"created_at"`
Messages []llm.Message `json:"messages,omitempty"`
PromptTokens int `json:"prompt_tokens,omitempty"`
CompletionTokens int `json:"completion_tokens,omitempty"`
// CompactionIdx is the index into Messages where the latest compaction boundary falls.
// Messages before this index have been summarized into CompactionSummary.
// Zero means no compaction has occurred.
CompactionIdx int `json:"compaction_idx,omitempty"`
CompactionSummary string `json:"compaction_summary,omitempty"`
// NoteEntries and TodoEntries are durable session state: unlike a tool result, they are
// not messages, so compaction cannot take them. The fields are named apart from the
// Notes/Todos accessors that implement agent.NoteStore; the JSON keys are the plain names.
NoteEntries []agent.Note `json:"notes,omitempty"`
TodoEntries []agent.Todo `json:"todos,omitempty"`
// AdditionalSystemPrompt records the extra system-prompt text this session actually ran
// under. It is a record — for the trace, and so a resumed session does not silently lose
// its identity when the flag that set it is not repeated — not the authority. Whoever
// assembles a run resolves it afresh, and the last writer wins.
AdditionalSystemPrompt string `json:"additional_system_prompt,omitempty"`
}
Session holds conversation history (user, assistant, tool messages) and metadata. The system message is not stored; it is prepended at call time by the agent. JSON tags match the on-disk session file format (snake_case).
func NewSession ¶
NewSession creates a new session with a generated UUID, the given title, created_at set to the current time, and empty history. Title may be empty.
func NewSessionFromData ¶
func NewSessionFromData(id, title string, createdAt time.Time, messages []llm.Message, promptTokens, completionTokens int) *Session
NewSessionFromData constructs a Session from persisted data.
func (*Session) AddCompaction ¶
AddCompaction advances the compaction boundary by summarizedCount messages and stores the summary. The summary is expected to subsume any earlier one, so replacing is correct. Implements agent.CompactionHistory so RunLoop can persist the boundary across turns.
func (*Session) HistoryMessages ¶
HistoryMessages returns the LLM-facing message slice. When a compaction boundary exists, only messages from CompactionIdx onward are returned; earlier messages have been summarized.
func (*Session) PriorSummary ¶
PriorSummary returns the summary stored by the most recent compaction, or "" when this session has never been compacted. Implements agent.CompactionHistory so RunLoop can feed the previous summary back into the next compaction instead of discarding what it covered.
func (*Session) SetNotes ¶
SetNotes replaces the session's notes, preserving the age of entries whose text is unchanged so a rewrite of the list does not make every entry look new. Implements agent.NoteStore.
type SessionItem ¶
type SessionItem struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
Workspace string `json:"workspace,omitempty"`
CreatedAt string `json:"created_at"` // RFC3339
Pinned bool `json:"pinned,omitempty"`
}
SessionItem is one session's metadata in the session index file (sessions.json).