chatstore

package
v2026.708.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 17 Imported by: 0

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 ApplyTurnUsageDisplayToLastAssistant

func ApplyTurnUsageDisplayToLastAssistant(s *Session, ctxTok, usrTok int64, ctxEst bool, reasonTok, respTok, totalTok 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 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 ChatIDHex

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

func ChatsDir

func ChatsDir(projectHex string) (string, error)

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 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 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 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 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 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 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 WriteActiveSubagents added in v2026.615.0

func WriteActiveSubagents(f *ActiveSubagentsFile) 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 Message

type Message struct {
	Role          string     `json:"role"`
	Content       string     `json:"content"`
	APIContent    string     `json:"api_content,omitempty"`
	ToolCallID    string     `json:"tool_call_id,omitempty"`
	ToolCalls     []ToolCall `json:"tool_calls,omitempty"`
	ReasoningText string     `json:"reasoning_text,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"`
	CachedPromptTokens int64   `json:"cached_prompt_tokens,omitempty"`
	OutputTPS          float64 `json:"output_tps,omitempty"`
	TTFTSecs           float64 `json:"ttft_secs,omitempty"`
	PromptTPS          float64 `json:"prompt_tps,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"`
	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"`
}

type PendingSubagentSpawn added in v2026.615.0

type PendingSubagentSpawn struct {
	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"`
	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 {
	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"`

	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"`
	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 ReadSession

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

func SessionWithLatestUserMessage

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

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 {
	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