Documentation
¶
Overview ¶
Package project 提供项目级别的外部记忆系统 用于存储项目上下文、用户偏好、工作流状态等信息 典型实现:AGENTS.md 文件模式
Index ¶
- type Entry
- type FileStore
- func (s *FileStore) AppendEntry(ctx context.Context, projectID string, section MemorySection, entry *Entry) error
- func (s *FileStore) Delete(ctx context.Context, projectID string) error
- func (s *FileStore) Exists(ctx context.Context, projectID string) (bool, error)
- func (s *FileStore) GetSummary(ctx context.Context, projectID string) (string, error)
- func (s *FileStore) GetVersionHistory(ctx context.Context, projectID string, limit int) ([]*ProjectMemory, error)
- func (s *FileStore) Load(ctx context.Context, projectID string) (*ProjectMemory, error)
- func (s *FileStore) RecordParams(ctx context.Context, projectID string, params *GenerationParams) error
- func (s *FileStore) Save(ctx context.Context, memory *ProjectMemory) error
- func (s *FileStore) UpdateWorkflowStep(ctx context.Context, projectID string, step *WorkflowStep) error
- type GenerationParams
- type MemorySection
- type ProjectMemory
- type Section
- type Store
- type StoreConfig
- type WorkflowStep
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
// ID 条目 ID
ID string `json:"id"`
// Category 分类(如 preference, constraint, style)
Category string `json:"category"`
// Content 内容
Content string `json:"content"`
// Value 结构化值(可选)
Value any `json:"value,omitempty"`
// Source 来源(dialog, choice, system)
Source string `json:"source"`
// Confidence 置信度
Confidence float64 `json:"confidence"`
// CreatedAt 创建时间
CreatedAt time.Time `json:"created_at"`
// Metadata 元数据
Metadata map[string]any `json:"metadata,omitempty"`
}
Entry 条目
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
FileStore 文件存储实现(AGENTS.md 模式)
func (*FileStore) AppendEntry ¶
func (s *FileStore) AppendEntry(ctx context.Context, projectID string, section MemorySection, entry *Entry) error
AppendEntry 追加条目到指定章节
func (*FileStore) GetSummary ¶
GetSummary 获取摘要(用于 AI 上下文注入)
func (*FileStore) GetVersionHistory ¶
func (s *FileStore) GetVersionHistory(ctx context.Context, projectID string, limit int) ([]*ProjectMemory, error)
GetVersionHistory 获取版本历史(文件存储不支持,返回空)
func (*FileStore) RecordParams ¶
func (s *FileStore) RecordParams(ctx context.Context, projectID string, params *GenerationParams) error
RecordParams 记录生成参数
func (*FileStore) Save ¶
func (s *FileStore) Save(ctx context.Context, memory *ProjectMemory) error
Save 保存项目记忆
func (*FileStore) UpdateWorkflowStep ¶
func (s *FileStore) UpdateWorkflowStep(ctx context.Context, projectID string, step *WorkflowStep) error
UpdateWorkflowStep 更新工作流步骤状态
type GenerationParams ¶
type GenerationParams struct {
// Model 模型名称
Model string `json:"model"`
// Temperature 温度
Temperature float64 `json:"temperature"`
// MaxTokens 最大 tokens
MaxTokens int `json:"max_tokens"`
// Extra 额外参数
Extra map[string]any `json:"extra,omitempty"`
// Timestamp 记录时间
Timestamp time.Time `json:"timestamp"`
}
GenerationParams 生成参数
type MemorySection ¶
type MemorySection string
MemorySection 记忆章节类型
const ( // SectionPreferences 用户偏好(从对话中提取) SectionPreferences MemorySection = "preferences" // SectionChoices 关键选择(用户在工作流中的选择) SectionChoices MemorySection = "choices" // SectionWorkflow 工作流状态 SectionWorkflow MemorySection = "workflow" // SectionParams 生成参数 SectionParams MemorySection = "params" // SectionHistory 项目历史 SectionHistory MemorySection = "history" // SectionCustom 自定义章节 SectionCustom MemorySection = "custom" )
type ProjectMemory ¶
type ProjectMemory struct {
// ProjectID 项目标识
ProjectID string `json:"project_id"`
// Title 项目标题
Title string `json:"title"`
// Description 项目描述
Description string `json:"description"`
// Sections 章节内容
Sections map[MemorySection]*Section `json:"sections"`
// Metadata 元数据
Metadata map[string]any `json:"metadata,omitempty"`
// CreatedAt 创建时间
CreatedAt time.Time `json:"created_at"`
// UpdatedAt 更新时间
UpdatedAt time.Time `json:"updated_at"`
// Version 版本号
Version int `json:"version"`
}
ProjectMemory 项目记忆
func NewProjectMemory ¶
func NewProjectMemory(projectID, title, description string) *ProjectMemory
NewProjectMemory 创建新的项目记忆
func (*ProjectMemory) AddEntry ¶
func (pm *ProjectMemory) AddEntry(section MemorySection, entry *Entry)
AddEntry 添加条目到指定章节
func (*ProjectMemory) GetEntries ¶
func (pm *ProjectMemory) GetEntries(section MemorySection) []*Entry
GetEntries 获取指定章节的所有条目
func (*ProjectMemory) GetSummary ¶
func (pm *ProjectMemory) GetSummary() string
GetSummary 获取摘要(用于注入 AI 上下文)
type Section ¶
type Section struct {
// Name 章节名称
Name string `json:"name"`
// Protected 是否受保护(不可自动删除)
Protected bool `json:"protected"`
// Entries 条目列表
Entries []*Entry `json:"entries"`
}
Section 章节
type Store ¶
type Store interface {
// Load 加载项目记忆
Load(ctx context.Context, projectID string) (*ProjectMemory, error)
// Save 保存项目记忆
Save(ctx context.Context, memory *ProjectMemory) error
// Delete 删除项目记忆
Delete(ctx context.Context, projectID string) error
// Exists 检查项目记忆是否存在
Exists(ctx context.Context, projectID string) (bool, error)
// AppendEntry 追加条目到指定章节
AppendEntry(ctx context.Context, projectID string, section MemorySection, entry *Entry) error
// UpdateWorkflowStep 更新工作流步骤状态
UpdateWorkflowStep(ctx context.Context, projectID string, step *WorkflowStep) error
// RecordParams 记录生成参数
RecordParams(ctx context.Context, projectID string, params *GenerationParams) error
// GetSummary 获取摘要(用于 AI 上下文注入)
GetSummary(ctx context.Context, projectID string) (string, error)
// GetVersionHistory 获取版本历史
GetVersionHistory(ctx context.Context, projectID string, limit int) ([]*ProjectMemory, error)
}
Store 项目记忆存储接口
type StoreConfig ¶
type StoreConfig struct {
// BasePath 基础路径(用于文件存储)
BasePath string
// FileName 文件名(默认 AGENTS.md)
FileName string
// Template 模板内容
Template string
// AutoCreate 是否自动创建
AutoCreate bool
}
StoreConfig 存储配置
type WorkflowStep ¶
type WorkflowStep struct {
// ID 步骤 ID
ID string `json:"id"`
// Name 步骤名称
Name string `json:"name"`
// Status 状态: pending, in_progress, completed, skipped
Status string `json:"status"`
// StartedAt 开始时间
StartedAt *time.Time `json:"started_at,omitempty"`
// CompletedAt 完成时间
CompletedAt *time.Time `json:"completed_at,omitempty"`
// Note 备注
Note string `json:"note,omitempty"`
}
WorkflowStep 工作流步骤
Click to show internal directories.
Click to hide internal directories.