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

session

package
v0.10.4 Latest Latest
Warning

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

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

Documentation

Overview

internal/session/browse.go

internal/session/compact.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	ID       string
	Parent   *Node `json:"-"`
	Children []*Node
	Message  ai.Message
	Usage    ai.Usage
	Created  time.Time
	// DurationMs is the wall-clock time of the turn that produced this node
	// (request start to stream end), in milliseconds. 0 for non-assistant nodes.
	DurationMs int
	// CompactedCount > 0 marks this node as a compaction summary that
	// replaced N prior messages along its branch.
	CompactedCount int
}

type Session

type Session struct {
	ID        string
	Name      string
	Created   time.Time
	Updated   time.Time
	Provider  string
	Model     string
	Effort    string
	Cwd       string
	Root      *Node
	Active    *Node
	Subagents []SubagentTask
	FilesRead []string
	// contains filtered or unexported fields
}

func Load

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

func LoadByID added in v0.5.3

func LoadByID(dir, id string) (*Session, error)

func New

func New(model string) *Session

func (*Session) Append

func (s *Session) Append(msg ai.Message) *Node

func (*Session) AppendWithUsage added in v0.7.1

func (s *Session) AppendWithUsage(msg ai.Message, usage ai.Usage, durationMs int) *Node

AppendWithUsage appends msg and records its token usage and turn duration in the same lock acquisition. Callers must not set Usage on the returned node themselves: once Append returns, the node is reachable by concurrent tree walkers (e.g. Save), so any later unlocked write races with them.

func (*Session) Clone

func (s *Session) Clone() *Session

func (*Session) Compact

func (s *Session) Compact(ctx context.Context, instructions string, summarize Summarizer) error

Compact replaces the active path's prefix up to (but not including) the most recent user message with a single synthetic assistant summary message.

func (*Session) Fork

func (s *Session) Fork(target *Node)

func (*Session) Path

func (s *Session) Path() string

func (*Session) PathToActive

func (s *Session) PathToActive() []ai.Message

PathToActive returns the messages from the first child of root down to Active (excluding root).

func (*Session) PathToActiveNodes

func (s *Session) PathToActiveNodes() []*Node

PathToActiveNodes returns the nodes from the first child of root down to Active (excluding root). Use when callers need per-node metadata (e.g. CompactedCount) that PathToActive's []ai.Message strips away.

func (*Session) RecordFileRead added in v0.2.0

func (s *Session) RecordFileRead(path string)

RecordFileRead prepends path to FilesRead, deduping and capping at 50. Called by tools/read.go on every successful read.

func (*Session) Save

func (s *Session) Save() error

func (*Session) SetEffort added in v0.8.0

func (s *Session) SetEffort(effort string)

SetEffort records the reasoning-effort level used for the most recent turn.

func (*Session) SetPath

func (s *Session) SetPath(p string)

SetPath assigns the file path used by Save. Callers in cmd/rune use this to place sessions under ~/.rune/sessions; tests use it to point at a temp dir.

func (*Session) SetSubagents

func (s *Session) SetSubagents(tasks []SubagentTask)

SetSubagents replaces the persisted subagent task metadata for this session.

func (*Session) SubagentTasks

func (s *Session) SubagentTasks() []SubagentTask

SubagentTasks returns a copy of the persisted subagent task metadata.

func (*Session) UsageStats added in v0.8.0

func (s *Session) UsageStats() UsageStats

UsageStats computes per-session usage metadata over the active branch.

type SubagentTask

type SubagentTask struct {
	ID           string     `json:"task_id"`
	Name         string     `json:"name"`
	FamiliarName string     `json:"familiar_name,omitempty"`
	AgentType    string     `json:"agent_type"`
	Status       string     `json:"status"`
	Dependencies []string   `json:"dependencies,omitempty"`
	CreatedAt    time.Time  `json:"created_at"`
	StartedAt    *time.Time `json:"started_at,omitempty"`
	CompletedAt  *time.Time `json:"completed_at,omitempty"`
	InputTokens  int        `json:"input_tokens,omitempty"`
	OutputTokens int        `json:"output_tokens,omitempty"`
	Summary      string     `json:"summary,omitempty"`
	Error        string     `json:"error,omitempty"`
}

SubagentTask is the durable, session-owned metadata for a subagent task. It intentionally omits full prompts/transcripts; those may contain large or sensitive context and can be added later as artifact references.

type Summarizer

type Summarizer func(ctx context.Context, history []ai.Message, instructions string) (string, error)

type Summary

type Summary struct {
	ID           string
	Name         string
	Preview      string
	Created      time.Time
	Updated      time.Time
	Path         string
	MessageCount int
	Model        string
	Cwd          string
}

func ListSessions

func ListSessions(dir string) ([]Summary, error)

func ListSessionsForCWD added in v0.1.16

func ListSessionsForCWD(dir, cwd string) ([]Summary, error)

type UsageStats added in v0.8.0

type UsageStats struct {
	Provider       string
	Model          string
	Effort         string
	Created        time.Time
	Updated        time.Time
	Turns          int
	Input          int
	Output         int
	CacheRead      int
	DurationMs     int
	SubagentCount  int
	SubagentInput  int
	SubagentOutput int
}

UsageStats aggregates token, latency, and turn metadata across the active branch (root → Active), plus subagent token totals for the whole session.

Jump to

Keyboard shortcuts

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