session

package
v0.0.0-...-38ea638 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MainSessionID = "main"

Variables

This section is empty.

Functions

func IsHiddenSession

func IsHiddenSession(sessionID string) bool

IsHiddenSession 系统/写手会话:不进侧栏历史列表。

func NormalizeSessionID

func NormalizeSessionID(raw string) string

NormalizeSessionID 空 / default → main。

func OrchKey

func OrchKey(projectID, sessionID string) string

OrchKey 编排键:orch:{projectId}:{sessionId}(与稿舍约定对齐)。

func ParseOrchKey

func ParseOrchKey(projectID, orch string) string

ParseOrchKey 从 orch:pid:sess 拆出 sessionId。

Types

type ContextBudget

type ContextBudget struct {
	// RecentKeep 最近原文条数(默认 12)。
	RecentKeep int
	// MaxMsgRunes 单条最大 rune(默认 2400)。
	MaxMsgRunes int
	// OlderUserKeep 更早历史里保留的 user 要点条数(默认 8)。
	OlderUserKeep int
	// OlderUserRunes 每条旧 user 摘要 rune(默认 160)。
	OlderUserRunes int
	// OlderAssistKeep 折叠区保留的助理结论条数(默认 4)。
	OlderAssistKeep int
	// OlderAssistRunes 每条助理结论 rune(默认 120)。
	OlderAssistRunes int
	// OlderToolKeep 折叠区保留的工具足迹条数(默认 8)。
	OlderToolKeep int
}

ContextBudget 构造 ContextMessages 预算(磁盘 sessions.json 仍全量保留)。

func DefaultContextBudget

func DefaultContextBudget() ContextBudget

DefaultContextBudget 默认有界 ContextMessages。

type ContextMessage

type ContextMessage struct {
	Role    string
	Content string
}

ContextMessage 喂给模型的一条进模上下文(与磁盘 Message 分离;可截断/摘要)。

func BuildContextMessages

func BuildContextMessages(msgs []Message, budget ContextBudget, lookup ToolDigestLookup) []ContextMessage

BuildContextMessages 从全量会话消息构造有界 ContextMessages(不含本轮尚未 Append 的 user)。 助理正文不含工具行;交付足迹经 lookup(taskId) 进 system,避免模型仿写 `[Desk tools:…]`。

type File

type File struct {
	ActiveID string    `json:"activeId"`
	Sessions []Session `json:"sessions"`
}

File 磁盘/库视图格式(API 兼容)。

type Message

type Message struct {
	Role           string `json:"role"` // user | assistant | system
	Content        string `json:"content"`
	CreatedAt      int64  `json:"createdAt"`
	TaskID         string `json:"taskId,omitempty"` // 助手回合对应 tasks 轨迹
	Seq            int    `json:"seq,omitempty"`
	InModelWindow  bool   `json:"inModelWindow"`
	HasFeedforward bool   `json:"hasFeedforward"`
}

Message 会话消息(工作记忆壳;正文进 ContextMessages;工具经 TaskID → tasks,禁止塞进 Content)。

type SearchOptions

type SearchOptions struct {
	Query     string
	Limit     int
	SessionID string // 空=全部会话
}

SearchOptions 会话对话检索(FTS5)。

type Session

type Session struct {
	ID        string    `json:"id"`
	Title     string    `json:"title"`
	OrchKey   string    `json:"orchKey"`
	UpdatedAt int64     `json:"updatedAt"`
	Messages  []Message `json:"messages"`
}

Session 一条 UI/编排会话。

type Store

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

Store 按项目 SQLite 会话。

func NewStore

func NewStore() *Store

func (*Store) ActiveBrief

func (s *Store) ActiveBrief(projectRoot, projectID string) (string, error)

ActiveBrief 供 MCP / UI / Turn Snapshot 短摘要。

func (*Store) Append

func (s *Store) Append(projectRoot, projectID, sessionID, role, content, taskID, feedforward string) (File, error)

Append 往 active(或指定)会话追加消息;写入 history_message(对话 SSOT)。

func (*Store) Clear

func (s *Store) Clear(projectRoot, projectID, sessionID string, deleteSession bool) (File, error)

Clear 清空指定会话消息;删会话时若清的是 active 则回落 main。

func (*Store) Create

func (s *Store) Create(projectRoot, projectID, title string) (File, Session, error)

Create 新建 sess-*。

func (*Store) Ensure

func (s *Store) Ensure(projectRoot, projectID, sessionID, title string) error

Ensure 确保会话存在;不切换 ActiveID。

func (*Store) FormatThreadBrief

func (s *Store) FormatThreadBrief(projectRoot, projectID string, usersOnly bool, maxUser int) (string, error)

FormatThreadBrief 最近用户原话。

func (*Store) Rewind

func (s *Store) Rewind(projectRoot, projectID, sessionID string, keep int) (File, error)

Rewind 截断会话消息,仅保留前 keep 条 UI 可见消息(及之前的 tool/system)。

func (*Store) Search

func (s *Store) Search(projectRoot, projectID string, opt SearchOptions) (string, error)

Search 按 FTS5 检索 history_message;MySQL 无 FTS 时走 LIKE。

func (*Store) SetActive

func (s *Store) SetActive(projectRoot, projectID, sessionID string) (File, error)

SetActive 切换 active 会话。

func (*Store) Snapshot

func (s *Store) Snapshot(projectRoot, projectID string) (File, error)

Snapshot 读写当前文件视图。

func (*Store) VisibleSnapshot

func (s *Store) VisibleSnapshot(projectRoot, projectID string) (File, error)

VisibleSnapshot 侧栏可见会话(过滤 once: / skill-reflect:)。

type ToolDigestLookup

type ToolDigestLookup func(taskID string) []string

ToolDigestLookup 按 taskId 取交付足迹(write_file→path …)。真源在 runs,不进助理正文。

Jump to

Keyboard shortcuts

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