Documentation
¶
Overview ¶
Package session — branch.go implements session branching. Branches allow creating divergent conversation paths from a fork point.
Package session provides a file-based session.Service implementation that persists sessions as JSONL files on disk.
Index ¶
- type BranchInfo
- type CompactConfig
- type FileService
- func (s *FileService) ATIFWriter(sessionID string) *atif.Writer
- func (s *FileService) ActiveBranch(sessionID string) string
- func (s *FileService) AppendEvent(_ context.Context, curSession session.Session, event *session.Event) error
- func (s *FileService) Compact(sessionID, appName, userID string, summarizer Summarizer, cfg CompactConfig) error
- func (s *FileService) Create(_ context.Context, req *session.CreateRequest) (*session.CreateResponse, error)
- func (s *FileService) CreateBranch(sessionID, appName, userID, branchName string) error
- func (s *FileService) Delete(_ context.Context, req *session.DeleteRequest) error
- func (s *FileService) EstimateTokens(sessionID, appName, userID string) (int, error)
- func (s *FileService) Get(_ context.Context, req *session.GetRequest) (*session.GetResponse, error)
- func (s *FileService) GetPlanContext(sessionID string) (*PlanContext, error)
- func (s *FileService) LastSessionID(appName, userID string) string
- func (s *FileService) List(_ context.Context, req *session.ListRequest) (*session.ListResponse, error)
- func (s *FileService) ListBranches(sessionID, appName, userID string) ([]BranchInfo, string, error)
- func (s *FileService) SwitchBranch(sessionID, appName, userID, branchName string) error
- func (s *FileService) UpdatePlanContext(sessionID string, ctx *PlanContext) error
- type Meta
- type PlanContext
- type Summarizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BranchInfo ¶
type BranchInfo struct {
Name string `json:"name"`
Head int `json:"head"` // index of the last event in this branch
Parent *string `json:"parent"` // parent branch name, nil for main
ForkPoint int `json:"forkPoint,omitempty"` // event index where this branch forked from parent
}
BranchInfo describes a named branch within a session.
type CompactConfig ¶
type CompactConfig struct {
// MaxTokens is the approximate token threshold that triggers compaction.
// Default: 100000.
MaxTokens int
// KeepRecent is the number of recent events to keep uncompacted.
// Default: 10.
KeepRecent int
}
CompactConfig controls when and how compaction runs.
func DefaultCompactConfig ¶
func DefaultCompactConfig() CompactConfig
DefaultCompactConfig returns sensible default compaction settings.
type FileService ¶
type FileService struct {
// contains filtered or unexported fields
}
FileService implements session.Service with file-based JSONL persistence. Sessions are stored in baseDir/<session-id>/ with meta.json and events.jsonl.
func NewFileService ¶
func NewFileService(baseDir string) (*FileService, error)
NewFileService creates a new file-based session service. baseDir is the directory where sessions are stored (e.g., ~/.pi-go/sessions).
func (*FileService) ATIFWriter ¶ added in v0.0.14
func (s *FileService) ATIFWriter(sessionID string) *atif.Writer
ATIFWriter returns the ATIF writer for the given session, or nil if not found.
func (*FileService) ActiveBranch ¶
func (s *FileService) ActiveBranch(sessionID string) string
ActiveBranch returns the name of the currently active branch.
func (*FileService) AppendEvent ¶
func (*FileService) Compact ¶
func (s *FileService) Compact(sessionID, appName, userID string, summarizer Summarizer, cfg CompactConfig) error
Compact checks if the session's events exceed the token threshold and, if so, summarizes older events using the provided summarizer function. The older events are replaced with a single summary event while recent events are preserved. The events file on disk is rewritten.
func (*FileService) Create ¶
func (s *FileService) Create(_ context.Context, req *session.CreateRequest) (*session.CreateResponse, error)
func (*FileService) CreateBranch ¶
func (s *FileService) CreateBranch(sessionID, appName, userID, branchName string) error
CreateBranch creates a new branch from the current position in the session. The new branch starts with a copy of events up to the current head of the active branch.
func (*FileService) Delete ¶
func (s *FileService) Delete(_ context.Context, req *session.DeleteRequest) error
func (*FileService) EstimateTokens ¶
func (s *FileService) EstimateTokens(sessionID, appName, userID string) (int, error)
EstimateTokens returns an approximate token count for a session's events. Uses a simple chars/4 heuristic.
func (*FileService) Get ¶
func (s *FileService) Get(_ context.Context, req *session.GetRequest) (*session.GetResponse, error)
func (*FileService) GetPlanContext ¶ added in v0.0.15
func (s *FileService) GetPlanContext(sessionID string) (*PlanContext, error)
GetPlanContext returns the plan context for the given session, or nil if not found.
func (*FileService) LastSessionID ¶
func (s *FileService) LastSessionID(appName, userID string) string
LastSessionID returns the most recently updated session ID, or "" if none.
func (*FileService) List ¶
func (s *FileService) List(_ context.Context, req *session.ListRequest) (*session.ListResponse, error)
func (*FileService) ListBranches ¶
func (s *FileService) ListBranches(sessionID, appName, userID string) ([]BranchInfo, string, error)
ListBranches returns all branches for a session.
func (*FileService) SwitchBranch ¶
func (s *FileService) SwitchBranch(sessionID, appName, userID, branchName string) error
SwitchBranch switches the active branch for a session. The session's in-memory events are replaced with the branch's events.
func (*FileService) UpdatePlanContext ¶ added in v0.0.15
func (s *FileService) UpdatePlanContext(sessionID string, ctx *PlanContext) error
UpdatePlanContext updates the plan session context in the session metadata. Pass nil to clear the context.
type Meta ¶
type Meta struct {
ID string `json:"id"`
AppName string `json:"appName"`
UserID string `json:"userID"`
WorkDir string `json:"workDir,omitempty"`
Model string `json:"model,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
PlanContext *PlanContext `json:"planContext,omitempty"`
}
Meta holds session metadata persisted in meta.json.
type PlanContext ¶ added in v0.0.15
type PlanContext struct {
TaskName string `json:"taskName,omitempty"`
RoughIdea string `json:"roughIdea,omitempty"`
SpecDir string `json:"specDir,omitempty"`
Phase string `json:"phase,omitempty"`
}
PlanContext holds the /plan session context for resume.
type Summarizer ¶
Summarizer is a function that takes a slice of events to be summarized and returns a summary text. This is typically backed by an LLM call.