chatstore

package
v2026.1114.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SubOriginParent    = "parent"
	SubOriginScheduled = "scheduled"
)
View Source
const (
	SubStatusRunning   = "running"
	SubStatusPaused    = "paused"
	SubStatusDone      = "done"
	SubStatusCancelled = "cancelled"
	SubStatusQueued    = "queued"
)

Variables

This section is empty.

Functions

func ApplyCompaction added in v2026.608.0

func ApplyCompaction(sess *Session, body string, at time.Time)

func ApplyCompactionWithPendingMessages added in v2026.1114.0

func ApplyCompactionWithPendingMessages(sess *Session, body string, at time.Time, pending []Message)

func ApplyTurnUsageDisplayToLastAssistant

func ApplyTurnUsageDisplayToLastAssistant(s *Session, ctxTok, usrTok int64, ctxEst bool, reasonTok, respTok, totalTok, cachedPromptTok, cacheCreationPromptTok int64, outputTPS, ttftSecs, promptTPS, turnWallSecs float64)

func ApplyTurnUsageDisplayToLastSubAssistant added in v2026.615.0

func ApplyTurnUsageDisplayToLastSubAssistant(s *SubSession, ctxTok, usrTok int64, ctxEst bool, reasonTok, respTok, totalTok, cachedPromptTok, cacheCreationPromptTok int64, outputTPS, ttftSecs, promptTPS, turnWallSecs float64)

func ArchiveUncompactedState added in v2026.608.0

func ArchiveUncompactedState(sess *Session, at time.Time)

func AssistantDisplayParts

func AssistantDisplayParts(m Message) (reasoning string, visibleContent string)

func BackfillAssistantUsageFromTextIfEmpty

func BackfillAssistantUsageFromTextIfEmpty(m *Message, prior []Message)

func BackfillSessionAssistantUsage

func BackfillSessionAssistantUsage(msgs []Message)

func CacheTokenCount added in v2026.1023.0

func CacheTokenCount(value int64, reported bool) int64

CacheTokenCount distinguishes legacy absent zero counters from reported zero.

func ChatIDHex

func ChatIDHex(title string, ts time.Time) string

func ChatsDir

func ChatsDir(projectHex string) (string, error)

func ConversationSummaryText added in v2026.1114.0

func ConversationSummaryText(body string) string

func DeleteResearchJob added in v2026.617.0

func DeleteResearchJob(projectHex, slug string) error

func EnsureResearchDir added in v2026.617.0

func EnsureResearchDir(projectHex string) (string, error)

func FinishSessionLoad

func FinishSessionLoad(s *Session) (repaired bool)

func IsCapabilityTool added in v2026.1021.0

func IsCapabilityTool(name string) bool

func IsCompactionSummary added in v2026.1021.0

func IsCompactionSummary(message Message) bool

IsCompactionSummary recognizes the stored summary envelope, rather than mentions of its marker in ordinary assistant explanations or tool output.

func IsPlaceholderChatID

func IsPlaceholderChatID(id string) bool

func ListResearchJobFiles added in v2026.617.0

func ListResearchJobFiles(projectHex string) ([]string, error)

func MessageCheckpointTagVisible

func MessageCheckpointTagVisible(m Message) bool

func MessageWireWeight added in v2026.611.1

func MessageWireWeight(m Message, includeReasoning bool, model string) int64

func MigrateImagePathsAfterChatRename

func MigrateImagePathsAfterChatRename(projectHex string, s *Session, oldChatID, newChatID string) error

func MigrateLegacyCheckpointsToBase0

func MigrateLegacyCheckpointsToBase0(s *Session)

func NeutralizeLiteralImgPlaceholders added in v2026.602.2

func NeutralizeLiteralImgPlaceholders(content string) string

func NewPlaceholderChatID

func NewPlaceholderChatID(t time.Time) string

func NormalizeSummaryWhitespace added in v2026.602.2

func NormalizeSummaryWhitespace(content string) string

func PlansDir

func PlansDir(projectHex string) (string, error)

func ProjectWelcomeStats

func ProjectWelcomeStats(projectHex string) (chatCount int, userSum, reasonSum, respSum int64, err error)

func PruneUnreferencedSessionImages

func PruneUnreferencedSessionImages(s *Session)

func ReadResearchJobFile added in v2026.617.0

func ReadResearchJobFile(projectHex, slug string, dest any) error

func RebuildProjectStats

func RebuildProjectStats(projectHex string) error

func ReconcileCheckpointLast

func ReconcileCheckpointLast(s *Session)

func RememberTerminalChat added in v2026.1023.0

func RememberTerminalChat(id, project, chat string) error

RememberTerminalChat keeps each terminal's active chat separate, including when several terminals share the same project during an upgrade.

func RemoveBrokenSessionImageFiles

func RemoveBrokenSessionImageFiles(s *Session) int

func RemoveSessionPath

func RemoveSessionPath(projectHex, chatID string) error

func RenameSessionFile

func RenameSessionFile(projectHex, oldID, newID string) (err error)

func RepairInterruptedToolCalls added in v2026.1023.0

func RepairInterruptedToolCalls(s *Session) int

RepairInterruptedToolCalls closes calls whose results were lost before a new user turn. It never executes a tool or claims that its side effects failed.

func RepairSessionMalformedImages

func RepairSessionMalformedImages(s *Session) (brokenDropped int, userMsgsAdjusted int, emptyRewrites int, imgNeutralized int)

func ResearchDir added in v2026.617.0

func ResearchDir(projectHex string) (string, error)

func ResearchHTMLPath added in v2026.617.0

func ResearchHTMLPath(projectHex, slug string) (string, error)

func ResearchJobPath added in v2026.617.0

func ResearchJobPath(projectHex, slug string) (string, error)

func RewriteEmptyUserMsgsAfterImageRepair

func RewriteEmptyUserMsgsAfterImageRepair(s *Session) int

func ScrubCompactSummaryContent added in v2026.602.2

func ScrubCompactSummaryContent(content string) string

func ScrubLiteralImgPlaceholdersForAPI added in v2026.602.2

func ScrubLiteralImgPlaceholdersForAPI(content string) string

func ScrubSummaryImgWorkflowLines added in v2026.602.2

func ScrubSummaryImgWorkflowLines(content string) string

func SessionActivityTime added in v2026.909.0

func SessionActivityTime(s *Session) time.Time

func SessionImgFragmentCount added in v2026.602.2

func SessionImgFragmentCount(s *Session) int

func SessionLockPath added in v2026.708.0

func SessionLockPath(projectHex, chatID string) (string, error)

func SessionPath

func SessionPath(projectHex, chatIDHex string) (string, error)

func SessionRepairChanged added in v2026.602.2

func SessionRepairChanged(brokenDropped, userMsgsAdjusted, emptyRewrites, imgNeutralized int) bool

func SessionValidImageTokenCount added in v2026.602.2

func SessionValidImageTokenCount(s *Session) int

func StoredUsageLineForTurnRange

func StoredUsageLineForTurnRange(msgs []Message, start, end int) (contextTok, lastUserTok, reasoningTok, responseTok, totalTok, cachedPromptTok, cacheCreationPromptTok int64, outputTPS, ttftSecs, promptTPS, turnWallSecs float64, contextEstimated bool, ok bool)

func StripAllImgPlaceholderLiterals added in v2026.602.2

func StripAllImgPlaceholderLiterals(content string) string

func StripFalseImgPlaceholdersFromNonUserSession added in v2026.602.2

func StripFalseImgPlaceholdersFromNonUserSession(s *Session) int

func StripStaleUserImgPlaceholdersFromSession

func StripStaleUserImgPlaceholdersFromSession(s *Session) int

func StripUnresolvedImgPlaceholders

func StripUnresolvedImgPlaceholders(content string, imageFiles map[int]string) string

func SubSessionPath added in v2026.615.0

func SubSessionPath(projectHex, origin, id string) (string, error)

func SubSessionRunning added in v2026.615.0

func SubSessionRunning(status string) bool

func SubchatID added in v2026.615.0

func SubchatID(parentChatID string, tc ToolCall, spawn time.Time) string

func SubchatPath

func SubchatPath(projectHex, idHex string) (string, error)

func SubchatsDir

func SubchatsDir(projectHex string) (string, error)

func SumCacheTokens added in v2026.1023.0

func SumCacheTokens(a, b int64) int64

SumCacheTokens returns unknown when any call lacks the counter.

func TempDir

func TempDir(projectHex string) (string, error)

func TouchProjectStatsAfterRemove

func TouchProjectStatsAfterRemove(projectHex, chatID string) error

func TouchProjectStatsAfterRename

func TouchProjectStatsAfterRename(projectHex, oldID, newID string) error

func ValidTerminalID added in v2026.1023.0

func ValidTerminalID(id string) bool

func WriteActiveSubagents added in v2026.615.0

func WriteActiveSubagents(f *ActiveSubagentsFile) (err error)

func WriteResearchJobFile added in v2026.617.0

func WriteResearchJobFile(projectHex string, slug string, v any) error

func WriteSession

func WriteSession(projectHex string, s *Session) (err error)

func WriteSubSession added in v2026.615.0

func WriteSubSession(projectHex string, s *SubSession) (err error)

Types

type ActiveSubagentEntry added in v2026.615.0

type ActiveSubagentEntry struct {
	ID          string    `json:"id"`
	Origin      string    `json:"origin"`
	Status      string    `json:"status"`
	SessionPath string    `json:"session_path"`
	ProjectHex  string    `json:"project_hex,omitempty"`
	SpawnedAt   time.Time `json:"spawned_at"`
}

type ActiveSubagentsFile added in v2026.615.0

type ActiveSubagentsFile struct {
	Agents []ActiveSubagentEntry `json:"agents"`
}

func ReadActiveSubagents added in v2026.615.0

func ReadActiveSubagents() (*ActiveSubagentsFile, error)

type BranchSegment added in v2026.621.0

type BranchSegment struct {
	ForkAtInclusive int       `json:"fork_at"`
	Messages        []Message `json:"messages"`
}

type CapabilityRegistry added in v2026.1021.0

type CapabilityRegistry struct {
	DiscoveredTools map[string]json.RawMessage `json:"discovered_tools,omitempty"`
	LoadedSkills    map[string]json.RawMessage `json:"loaded_skills,omitempty"`
	DisabledSkills  map[string]bool            `json:"disabled_skills,omitempty"`
	SDK             json.RawMessage            `json:"sdk,omitempty"`
}

func (*CapabilityRegistry) Backfill added in v2026.1021.0

func (r *CapabilityRegistry) Backfill(messages []Message)

func (*CapabilityRegistry) Capture added in v2026.1021.0

func (r *CapabilityRegistry) Capture(name, payload string)

func (*CapabilityRegistry) CaptureUser added in v2026.1021.0

func (r *CapabilityRegistry) CaptureUser(m Message)

func (CapabilityRegistry) RestoreMessage added in v2026.1021.0

func (r CapabilityRegistry) RestoreMessage() (Message, bool)

func (*CapabilityRegistry) SetSkillEnabled added in v2026.1023.1

func (r *CapabilityRegistry) SetSkillEnabled(name string, enabled bool)

type FileChangeLedger added in v2026.1023.0

type FileChangeLedger struct {
	AddedLines   map[string]int `json:"added_lines,omitempty"`
	RemovedLines map[string]int `json:"removed_lines,omitempty"`
	Binary       bool           `json:"binary,omitempty"`
	BeforeExists bool           `json:"before_exists"`
	AfterExists  bool           `json:"after_exists"`
}

FileChangeLedger stores only this chat's tool deltas, never workspace totals.

type FileChangeSummary added in v2026.1023.0

type FileChangeSummary struct {
	Path         string   `json:"path"`
	Added        int      `json:"added"`
	Removed      int      `json:"removed"`
	Binary       bool     `json:"binary,omitempty"`
	AddedLines   []string `json:"addedLines,omitempty"`
	RemovedLines []string `json:"removedLines,omitempty"`
}

FileChangeSummary is a saved view of this chat's pending changes at turn end.

type Message

type Message struct {
	FileChangesRecorded bool                `json:"file_changes_recorded,omitempty"`
	FileChanges         []FileChangeSummary `json:"file_changes,omitempty"`
	ContextKind         string              `json:"context_kind,omitempty"`
	Provider            string              `json:"provider,omitempty"`
	FastMode            *bool               `json:"fast_mode,omitempty"`
	ReasoningEffort     string              `json:"reasoning_effort,omitempty"`
	Model               string              `json:"model,omitempty"`
	GUIHidden           bool                `json:"gui_hidden,omitempty"`
	CreatedAt           time.Time           `json:"created_at,omitempty"`
	Role                string              `json:"role"`
	Content             string              `json:"content"`
	APIContent          string              `json:"api_content,omitempty"`
	ToolCallID          string              `json:"tool_call_id,omitempty"`
	ToolImages          []images.Attachment `json:"tool_images,omitempty"`
	MediaPreviews       []images.Attachment `json:"media_previews,omitempty"`
	MediaRoot           string              `json:"media_root,omitempty"`
	ToolCalls           []ToolCall          `json:"tool_calls,omitempty"`
	ReasoningText       string              `json:"reasoning_text,omitempty"`
	ReasoningEncrypted  string              `json:"reasoning_encrypted,omitempty"`
	ReasoningItem       string              `json:"reasoning_item,omitempty"`
	AnthropicThinking   []json.RawMessage   `json:"anthropic_thinking,omitempty"`

	CheckpointSeq       int    `json:"cp_seq,omitempty"`
	CpSeqSet            bool   `json:"cp_set,omitempty"`
	CheckpointBranchKey string `json:"cp_branch,omitempty"`
	CommitOID           string `json:"commit_oid,omitempty"`

	UserPromptTokens          int64   `json:"user_prompt_tokens"`
	ReasoningTokens           int64   `json:"reasoning_tokens"`
	ResponseTokens            int64   `json:"response_tokens"`
	TurnTotalTokens           int64   `json:"turn_total_tokens"`
	PromptTokens              int64   `json:"prompt_tokens,omitempty"`
	CacheUsageTracked         bool    `json:"cache_usage_tracked,omitempty"`
	CachedPromptTokens        int64   `json:"cached_prompt_tokens,omitempty"`
	CacheCreationPromptTokens int64   `json:"cache_creation_prompt_tokens,omitempty"`
	OutputTPS                 float64 `json:"output_tps,omitempty"`
	TTFTSecs                  float64 `json:"ttft_secs,omitempty"`
	PromptTPS                 float64 `json:"prompt_tps,omitempty"`
	ToolWallSecs              float64 `json:"tool_wall_secs,omitempty"`
	TurnWallSecs              float64 `json:"turn_wall_secs,omitempty"`

	TurnDisplaySaved              bool    `json:"turn_display_saved,omitempty"`
	TurnContextTokens             int64   `json:"turn_context_tokens,omitempty"`
	TurnContextEst                bool    `json:"turn_context_est,omitempty"`
	TurnUserTokens                int64   `json:"turn_user_tokens,omitempty"`
	TurnCachedPromptTokens        int64   `json:"turn_cached_prompt_tokens,omitempty"`
	TurnCacheCreationPromptTokens int64   `json:"turn_cache_creation_prompt_tokens,omitempty"`
	TurnReasonTokens              int64   `json:"turn_reason_tokens,omitempty"`
	TurnRespTokens                int64   `json:"turn_resp_tokens,omitempty"`
	TurnTotalDisplay              int64   `json:"turn_total_display,omitempty"`
	TurnOutputTPS                 float64 `json:"turn_output_tps,omitempty"`
	TurnTTFTSecs                  float64 `json:"turn_ttft_secs,omitempty"`
	TurnPromptTPS                 float64 `json:"turn_prompt_tps,omitempty"`
	TurnWallDisplay               float64 `json:"turn_wall_display_secs,omitempty"`
}

func SummaryMessages added in v2026.1021.0

func SummaryMessages(messages []Message) []Message

type PendingSubagentSpawn added in v2026.615.0

type PendingSubagentSpawn struct {
	ParentSubchatID    string    `json:"parent_subchat_id,omitempty"`
	Depth              int       `json:"depth,omitempty"`
	RequesterSubchatID string    `json:"requester_subchat_id"`
	RequesterOrigin    string    `json:"requester_origin"`
	ParentChatID       string    `json:"parent_chat_id,omitempty"`
	ProjectHex         string    `json:"project_hex,omitempty"`
	SysPromptPath      string    `json:"sys_prompt_path"`
	Task               string    `json:"task"`
	Resume             string    `json:"resume,omitempty"`
	Interrupt          bool      `json:"interrupt,omitempty"`
	RunInBackground    bool      `json:"run_in_background,omitempty"`
	ReasoningEffort    string    `json:"reasoning_effort,omitempty"`
	RoleProvider       string    `json:"role_provider,omitempty"`
	RoleModel          string    `json:"role_model,omitempty"`
	ToolCall           ToolCall  `json:"tool_call"`
	SpawnISO           string    `json:"spawn_iso"`
	NotifyNewChat      bool      `json:"notify_new_chat,omitempty"`
	CreatedAt          time.Time `json:"created_at"`
}

type QueuedTask added in v2026.615.0

type QueuedTask struct {
	Task          string    `json:"task"`
	SysPromptPath string    `json:"sys_prompt_path,omitempty"`
	EnqueuedAt    time.Time `json:"enqueued_at"`
}

type Session

type Session struct {
	FileChanges       map[string]FileChangeLedger `json:"file_changes,omitempty"`
	FileChangesTurn   int                         `json:"file_changes_turn,omitempty"`
	ID                string                      `json:"id"`
	Title             string                      `json:"title"`
	CreatedAt         time.Time                   `json:"created_at"`
	LastMessageAt     time.Time                   `json:"last_message_at"`
	LastUserMessageAt time.Time                   `json:"last_user_message_at,omitempty"`
	Messages          []Message                   `json:"messages"`
	Capabilities      CapabilityRegistry          `json:"capabilities,omitempty"`

	CheckpointLast           int               `json:"checkpoint_last"`
	CheckpointCP0            bool              `json:"cp0,omitempty"`
	CheckpointBranchSuffix   string            `json:"cp_branch_suffix,omitempty"`
	ForkChildCount           map[int]int       `json:"fork_child_count,omitempty"`
	Branches                 []BranchSegment   `json:"branches,omitempty"`
	LastCommitOID            string            `json:"last_commit_oid,omitempty"`
	ImageSeq                 int               `json:"image_seq,omitempty"`
	ImageFiles               map[int]string    `json:"image_files,omitempty"`
	TerminalClips            map[string]string `json:"terminal_clips,omitempty"`
	ActivatedInstructionDirs []string          `json:"activated_instruction_dirs,omitempty"`
	UncompactedRaw           []UncompactedDump `json:"uncompactedRaw,omitempty"`

	PlanningActive   bool   `json:"planning_active,omitempty"`
	ActivePlanName   string `json:"active_plan_name,omitempty"`
	PlanImplementing bool   `json:"plan_implementing,omitempty"`
}

func FindByTitle

func FindByTitle(projectHex, title string) (*Session, error)

func ListRecent

func ListRecent(projectHex string, n int) ([]*Session, error)

func ListSummaries added in v2026.1114.0

func ListSummaries(projectHex string, limit int) ([]*Session, error)

func ReadSession

func ReadSession(projectHex, chatIDHex string) (sess *Session, err error)

func ReadTerminalChat added in v2026.1023.0

func ReadTerminalChat(id, project string) (*Session, error)

func SessionWithLatestUserMessage

func SessionWithLatestUserMessage(projectHex string) (*Session, error)

func (*Session) TruncateForRegeneration added in v2026.1030.0

func (s *Session) TruncateForRegeneration() error

Keep the original user message so expanded mentions, image references and checkpoint metadata remain identical on the new attempt.

func (*Session) UnmarshalJSON added in v2026.621.0

func (s *Session) UnmarshalJSON(data []byte) error

type SessionFileLock added in v2026.708.0

type SessionFileLock struct {
	// contains filtered or unexported fields
}

func TryAcquireSessionFileLock added in v2026.708.0

func TryAcquireSessionFileLock(projectHex, chatID string) (*SessionFileLock, error)

func (*SessionFileLock) Release added in v2026.708.0

func (l *SessionFileLock) Release()

type SubSession added in v2026.615.0

type SubSession struct {
	ParentSubchatID  string                 `json:"parent_subchat_id,omitempty"`
	Depth            int                    `json:"depth,omitempty"`
	FastMode         *bool                  `json:"fast_mode,omitempty"`
	Capabilities     CapabilityRegistry     `json:"capabilities,omitempty"`
	ID               string                 `json:"id"`
	Title            string                 `json:"title"`
	CreatedAt        time.Time              `json:"created_at"`
	LastMessageAt    time.Time              `json:"last_message_at"`
	Messages         []Message              `json:"messages"`
	ImageSeq         int                    `json:"image_seq,omitempty"`
	ImageFiles       map[int]string         `json:"image_files,omitempty"`
	ParentChatID     string                 `json:"parent_chat_id,omitempty"`
	ParentToolCallID string                 `json:"parent_tool_call_id,omitempty"`
	ProjectHex       string                 `json:"project_hex,omitempty"`
	SysPromptPath    string                 `json:"sys_prompt_path,omitempty"`
	Origin           string                 `json:"origin"`
	ScheduledAt      *time.Time             `json:"scheduled_at,omitempty"`
	PersistContext   bool                   `json:"persist_context,omitempty"`
	Status           string                 `json:"status"`
	TaskQueue        []QueuedTask           `json:"task_queue,omitempty"`
	ReasoningEffort  string                 `json:"reasoning_effort,omitempty"`
	RoleProvider     string                 `json:"role_provider,omitempty"`
	RoleModel        string                 `json:"role_model,omitempty"`
	PendingSpawns    []PendingSubagentSpawn `json:"pending_spawns,omitempty"`
}

func FindSubSessionByID added in v2026.615.0

func FindSubSessionByID(projectHex, id string) (*SubSession, error)

func ListSubSessions added in v2026.615.0

func ListSubSessions(projectHex string) ([]*SubSession, error)

func ReadSubSession added in v2026.615.0

func ReadSubSession(projectHex, origin, id string) (*SubSession, error)

type ToolCall

type ToolCall struct {
	ID        string `json:"id,omitempty"`
	Name      string `json:"name"`
	Arguments string `json:"arguments"`

	CheckpointSeq       int    `json:"cp_seq,omitempty"`
	CpSeqSet            bool   `json:"cp_set,omitempty"`
	CheckpointBranchKey string `json:"cp_branch,omitempty"`
}

type UncompactedDump added in v2026.608.0

type UncompactedDump struct {
	CompactAt              time.Time       `json:"compact_at"`
	Messages               []Message       `json:"messages"`
	CheckpointLast         int             `json:"checkpoint_last"`
	CheckpointCP0          bool            `json:"cp0,omitempty"`
	CheckpointBranchSuffix string          `json:"cp_branch_suffix,omitempty"`
	ForkChildCount         map[int]int     `json:"fork_child_count,omitempty"`
	Branches               []BranchSegment `json:"branches,omitempty"`
	LastCommitOID          string          `json:"last_commit_oid,omitempty"`
}

func (*UncompactedDump) UnmarshalJSON added in v2026.621.0

func (d *UncompactedDump) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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