Documentation
¶
Overview ¶
Package session is the Stage-1 namespace for session-lifecycle types in package engine. See ../REFACTOR_PLAN.md.
Index ¶
- func ExtractKeyFacts(messages []CompressMessage) []string
- func FormatCompressed(result *CompressionResult) string
- func ScoreImportance(msg CompressMessage, position int, total int) float64
- type CompressMessage
- type CompressStrategy
- type CompressedBlock
- type CompressionResult
- type Compressor
- type CrossSessionLearner
- func (c *CrossSessionLearner) BuildSessionPrimer(task string) string
- func (c *CrossSessionLearner) Decay(factor float64)
- func (c *CrossSessionLearner) GetConventions() []SessionConvention
- func (c *CrossSessionLearner) GetFailureResolutions(errorMsg string) []FailurePattern
- func (c *CrossSessionLearner) GetRelevantInsights(task string, limit int) []Insight
- func (c *CrossSessionLearner) LearnConvention(rule string, examples []string, source string)
- func (c *CrossSessionLearner) LearnFromOutcome(task, approach string, success bool, toolsUsed []string, ...)
- func (c *CrossSessionLearner) Load() error
- func (c *CrossSessionLearner) RecordFailure(pattern, context, resolution string)
- func (c *CrossSessionLearner) Save() error
- func (c *CrossSessionLearner) Stats() LearnerStats
- type FailurePattern
- type Insight
- type LearnerStats
- type SessionCompressor
- type SessionConvention
- type Timeline
- func (t *Timeline) AddAction(tool, target string, duration time.Duration)
- func (t *Timeline) AddDecision(decision, reason string)
- func (t *Timeline) AddError(err string)
- func (t *Timeline) AddEvent(eventType, content string, metadata map[string]string)
- func (t *Timeline) AddFileChange(path, action string)
- func (t *Timeline) AddMilestone(description string)
- func (t *Timeline) Duration() time.Duration
- func (t *Timeline) GetBetween(start, end time.Time) []TimelineEvent
- func (t *Timeline) GetByType(eventType string) []TimelineEvent
- func (t *Timeline) GetMilestones() []TimelineEvent
- func (t *Timeline) RenderTimeline(maxWidth int) string
- func (t *Timeline) Summarize() string
- type TimelineEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractKeyFacts ¶
func ExtractKeyFacts(messages []CompressMessage) []string
ExtractKeyFacts pulls out important facts from a group of messages: decisions made, files modified, errors encountered and resolved, conventions established.
func FormatCompressed ¶
func FormatCompressed(result *CompressionResult) string
FormatCompressed produces a human-readable summary of the compression result.
func ScoreImportance ¶
func ScoreImportance(msg CompressMessage, position int, total int) float64
ScoreImportance assigns an importance score to a message based on its content and position.
Types ¶
type CompressMessage ¶
type CompressMessage struct {
Role string
Content string
ToolName string
IsToolResult bool
Importance float64
Tokens int
}
CompressMessage represents a single message in the conversation for compression.
func SelectiveCompress ¶
func SelectiveCompress(messages []CompressMessage, budget int) []CompressMessage
SelectiveCompress keeps high-importance messages verbatim and summarizes low-importance blocks.
func SemanticCompress ¶
func SemanticCompress(messages []CompressMessage, budget int) []CompressMessage
SemanticCompress groups messages by topic/task, keeps conclusions, and summarizes journeys.
func TieredCompress ¶
func TieredCompress(messages []CompressMessage, budget int) []CompressMessage
TieredCompress applies different compression levels based on message recency. Recent (last 20%): keep verbatim Middle (20-60%): selective (keep important, summarize rest) Old (60-100%): aggressive summary
type CompressStrategy ¶
type CompressStrategy string
CompressStrategy defines the compression approach to use.
const ( // StrategySummarize compresses by summarizing all old messages into blocks. StrategySummarize CompressStrategy = "summarize" // StrategySelective keeps high-importance messages and summarizes the rest. StrategySelective CompressStrategy = "selective" // StrategyTiered applies different levels of compression based on recency. StrategyTiered CompressStrategy = "tiered" // StrategySemantic groups messages by topic and keeps conclusions. StrategySemantic CompressStrategy = "semantic" )
type CompressedBlock ¶
type CompressedBlock struct {
Summary string
OriginalCount int
TokensSaved int
KeyFacts []string
ToolCallSummary string
FilesDiscussed []string
}
CompressedBlock represents a group of messages that have been compressed into a summary.
func SummarizeBlock ¶
func SummarizeBlock(messages []CompressMessage) *CompressedBlock
SummarizeBlock creates a CompressedBlock from a group of messages by extracting key information.
type CompressionResult ¶
type CompressionResult struct {
Original int
Compressed int
TokensSaved int
Blocks []CompressedBlock
PreservedMessages int
}
CompressionResult holds statistics and details about a compression operation.
type Compressor ¶
type Compressor = SessionCompressor
Compressor is a shorter name for SessionCompressor.
func NewCompressor ¶
func NewCompressor(strategy CompressStrategy) *Compressor
NewCompressor returns a session compressor using the named strategy.
type CrossSessionLearner ¶
type CrossSessionLearner struct {
Insights []Insight `json:"insights"`
Conventions []SessionConvention `json:"conventions"`
FailurePatterns []FailurePattern `json:"failure_patterns"`
Dir string `json:"-"`
// contains filtered or unexported fields
}
CrossSessionLearner transfers insights, conventions, and patterns across sessions.
func NewCrossSessionLearner ¶
func NewCrossSessionLearner(dir string) *CrossSessionLearner
NewCrossSessionLearner creates a new CrossSessionLearner that persists data in dir.
func (*CrossSessionLearner) BuildSessionPrimer ¶
func (c *CrossSessionLearner) BuildSessionPrimer(task string) string
BuildSessionPrimer formats all relevant learning for injection into a new session.
func (*CrossSessionLearner) Decay ¶
func (c *CrossSessionLearner) Decay(factor float64)
Decay reduces confidence of old unused insights by the given factor.
func (*CrossSessionLearner) GetConventions ¶
func (c *CrossSessionLearner) GetConventions() []SessionConvention
GetConventions returns all learned conventions.
func (*CrossSessionLearner) GetFailureResolutions ¶
func (c *CrossSessionLearner) GetFailureResolutions(errorMsg string) []FailurePattern
GetFailureResolutions finds past failures matching an error message and returns them with their resolutions.
func (*CrossSessionLearner) GetRelevantInsights ¶
func (c *CrossSessionLearner) GetRelevantInsights(task string, limit int) []Insight
GetRelevantInsights returns insights relevant to the current task, scored by keyword overlap, confidence, and recency.
func (*CrossSessionLearner) LearnConvention ¶
func (c *CrossSessionLearner) LearnConvention(rule string, examples []string, source string)
LearnConvention records a project convention discovered during a session.
func (*CrossSessionLearner) LearnFromOutcome ¶
func (c *CrossSessionLearner) LearnFromOutcome(task, approach string, success bool, toolsUsed []string, filesModified []string)
LearnFromOutcome records the result of a task attempt. If successful, it extracts an insight about what worked. If failed, it records a failure pattern.
func (*CrossSessionLearner) Load ¶
func (c *CrossSessionLearner) Load() error
Load restores the learner state from disk.
func (*CrossSessionLearner) RecordFailure ¶
func (c *CrossSessionLearner) RecordFailure(pattern, context, resolution string)
RecordFailure records a failure pattern and how it was resolved.
func (*CrossSessionLearner) Save ¶
func (c *CrossSessionLearner) Save() error
Save persists the learner state to disk.
func (*CrossSessionLearner) Stats ¶
func (c *CrossSessionLearner) Stats() LearnerStats
Stats returns aggregate statistics about the learner.
type FailurePattern ¶
type FailurePattern struct {
ID string `json:"id"`
Pattern string `json:"pattern"`
Context string `json:"context"`
Resolution string `json:"resolution"`
Language string `json:"language"`
Occurrences int `json:"occurrences"`
LastSeen time.Time `json:"last_seen"`
}
FailurePattern represents a recorded failure and its resolution.
type Insight ¶
type Insight struct {
ID string `json:"id"`
Content string `json:"content"`
Category string `json:"category"` // "approach", "tool_usage", "avoidance", "preference"
Language string `json:"language"`
Confidence float64 `json:"confidence"`
SuccessCount int `json:"success_count"`
CreatedAt time.Time `json:"created_at"`
LastUsed time.Time `json:"last_used"`
}
Insight represents a learned insight from a previous session.
type LearnerStats ¶
type LearnerStats struct {
InsightCount int `json:"insight_count"`
ConventionCount int `json:"convention_count"`
FailureCount int `json:"failure_count"`
AvgConfidence float64 `json:"avg_confidence"`
}
LearnerStats holds aggregate statistics about the cross-session learner.
type SessionCompressor ¶
type SessionCompressor struct {
Strategy CompressStrategy
PreservePatterns []string
MinMessages int
// contains filtered or unexported fields
}
SessionCompressor performs intelligent session compression using configurable strategies.
func NewSessionCompressor ¶
func NewSessionCompressor(strategy CompressStrategy) *SessionCompressor
NewSessionCompressor creates a new compressor with the given strategy.
func (*SessionCompressor) Compress ¶
func (sc *SessionCompressor) Compress(messages []CompressMessage, budget int) (*CompressionResult, []CompressMessage, error)
Compress applies the configured strategy to reduce messages to fit within the token budget. It returns the compression result with statistics and the new compressed message list.
type SessionConvention ¶
type SessionConvention struct {
ID string `json:"id"`
Rule string `json:"rule"`
Examples []string `json:"examples"`
Source string `json:"source"`
Confidence float64 `json:"confidence"`
AppliedCount int `json:"applied_count"`
}
SessionConvention represents a project convention discovered during a session.
type Timeline ¶
type Timeline struct {
Events []TimelineEvent `json:"events"`
SessionID string `json:"session_id"`
StartTime time.Time `json:"start_time"`
// contains filtered or unexported fields
}
Timeline tracks a chronological sequence of events during a session.
func NewTimeline ¶
NewTimeline creates a new Timeline for the given session ID.
func (*Timeline) AddDecision ¶
AddDecision records a decision with its reasoning.
func (*Timeline) AddEvent ¶
AddEvent records a generic event with the given type, content, and metadata.
func (*Timeline) AddFileChange ¶
AddFileChange records a file system change (create, modify, or delete).
func (*Timeline) AddMilestone ¶
AddMilestone records a significant milestone in the session.
func (*Timeline) GetBetween ¶
func (t *Timeline) GetBetween(start, end time.Time) []TimelineEvent
GetBetween returns all events between start and end times (inclusive).
func (*Timeline) GetByType ¶
func (t *Timeline) GetByType(eventType string) []TimelineEvent
GetByType returns all events matching the given type.
func (*Timeline) GetMilestones ¶
func (t *Timeline) GetMilestones() []TimelineEvent
GetMilestones returns all milestone events.
func (*Timeline) RenderTimeline ¶
RenderTimeline produces a human-readable chronological view of the session.
type TimelineEvent ¶
type TimelineEvent struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"` // "action", "decision", "milestone", "error", "user_input", "file_change"
Content string `json:"content"`
Duration time.Duration `json:"duration,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
TimelineEvent represents a single event in a session timeline.