memoryinbox

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package memoryinbox 实现 Memory Inbox 聚合投影。

Inbox item 由现有 proposal、memory lifecycle、feedback、conflict、receipt 和 activity state 投影而成。它不是新的 truth store——只有无法从既有状态 重建的用户 review decision 才允许进入 additive GORM state。

分类规则是 deterministic 的,输出 category、reason_codes、risk、 source_coverage、suggested_action。

Index

Constants

View Source
const InboxSchemaVersion = "yeisme.memory_inbox.v1"

InboxSchemaVersion 是 memory inbox 的 schema 版本。

Variables

This section is empty.

Functions

func SummaryLine

func SummaryLine(pack InboxPack) string

SummaryLine 返回 inbox pack 的一行摘要。

Types

type AggregateInput

type AggregateInput struct {
	Proposals []agentmemory.AgentProposalRow
	Memories  []agentprotocol.MemoryRecord
}

AggregateInput 描述聚合输入(由 app service 从 store 收集)。

type Aggregator

type Aggregator struct{}

Aggregator 从现有 proposals、memories、conflicts、feedback 和 receipts 投影 inbox items。它不创建第二套 canonical store。

func NewAggregator

func NewAggregator() *Aggregator

NewAggregator 构造 aggregator。

func (*Aggregator) Aggregate

func (a *Aggregator) Aggregate(ctx context.Context, input AggregateInput, limit int) (InboxPack, error)

Aggregate 将 proposals + memories 投影为 bounded inbox pack。 分类是 deterministic 的:同输入同输出。

type InboxCategory

type InboxCategory string

InboxCategory 是 inbox item 的分类。

const (
	CategoryNewFact    InboxCategory = "new_fact"
	CategoryPreference InboxCategory = "preference"
	CategoryDecision   InboxCategory = "decision"
	CategoryLesson     InboxCategory = "lesson"
	CategoryCommitment InboxCategory = "commitment"
	CategoryConflict   InboxCategory = "conflict"
	CategoryDuplicate  InboxCategory = "duplicate"
	CategoryStale      InboxCategory = "stale"
	CategoryExpired    InboxCategory = "expired"
)

func AllCategories

func AllCategories() []InboxCategory

AllCategories 返回所有支持的分类,按确定性顺序。

type InboxItem

type InboxItem struct {
	SchemaVersion string        `json:"schema_version"`
	ItemID        string        `json:"item_id"`
	Category      InboxCategory `json:"category"`
	ReasonCodes   []ReasonCode  `json:"reason_codes"`
	Risk          RiskLevel     `json:"risk"`
	// Subject 是 item 的简短描述(脱敏,不含 body)。
	Subject string `json:"subject"`
	// Scope 是 item 所属的范围。
	Scope agentprotocol.Scope `json:"scope"`
	// SourceCoverage 描述来源解析情况。
	SourceCoverage SourceCoverage `json:"source_coverage"`
	// SuggestedAction 是建议的下一步操作。
	SuggestedAction SuggestedAction `json:"suggested_action"`
	// ProposalID 关联的 proposal ID(如有)。
	ProposalID string `json:"proposal_id,omitempty"`
	// MemoryID 关联的 memory ID(如有)。
	MemoryID string `json:"memory_id,omitempty"`
	// HandoffID 关联的 handoff ID(如有)。
	HandoffID string `json:"handoff_id,omitempty"`
	// ReceiptID 关联的 receipt ID(如有,用于 restore)。
	ReceiptID string `json:"receipt_id,omitempty"`
	// CreatedAt item 创建时间。
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt item 最后更新时间。
	UpdatedAt time.Time `json:"updated_at"`
	// ReviewVersion 用于乐观锁。
	ReviewVersion int `json:"review_version"`
	// Experimental 标记此 surface 为实验性。
	Experimental bool `json:"experimental"`
}

InboxItem 是 inbox 中的一个条目投影。 不包含 proposal body 或完整 memory 内容。

func (InboxItem) Validate

func (item InboxItem) Validate() error

Validate 检查 inbox item 的必填字段。

type InboxPack

type InboxPack struct {
	SchemaVersion string      `json:"schema_version"`
	Items         []InboxItem `json:"items"`
	// CountsByCategory 按 category 统计。
	CountsByCategory map[InboxCategory]int `json:"counts_by_category"`
	// TotalItems 是 item 总数。
	TotalItems int `json:"total_items"`
	// HighRiskCount 是高风险 item 数。
	HighRiskCount int `json:"high_risk_count"`
	// Truncated 表示是否因 limit 截断。
	Truncated bool `json:"truncated"`
	// Experimental 标记此 surface 为实验性。
	Experimental bool `json:"experimental"`
}

InboxPack 是 inbox 的 bounded 投影。

func (*InboxPack) ComputeCounts

func (p *InboxPack) ComputeCounts()

ComputeCounts 重新计算 CountsByCategory 和 HighRiskCount。

func (InboxPack) SortedItems

func (p InboxPack) SortedItems() []InboxItem

SortedItems 返回按 category 优先级和 risk 排序的 items 副本。 顺序:conflict > duplicate > stale/expired > new/preference/decision/lesson/commitment。 高风险优先于低风险。

func (InboxPack) Validate

func (p InboxPack) Validate() error

Validate 检查 inbox pack 的完整性。

type ReasonCode

type ReasonCode string

ReasonCode 是分类的稳定原因码,解释为什么进入该分类。

const (
	ReasonNewProposal       ReasonCode = "new_proposal"
	ReasonUnconfirmed       ReasonCode = "unconfirmed"
	ReasonConflictDetected  ReasonCode = "conflict_detected"
	ReasonDuplicateSubject  ReasonCode = "duplicate_subject"
	ReasonStaleSource       ReasonCode = "stale_source"
	ReasonExpiryReached     ReasonCode = "expiry_reached"
	ReasonConflictingScope  ReasonCode = "conflicting_scope"
	ReasonCrossScopePromo   ReasonCode = "cross_scope_promotion"
	ReasonBulkActionBlocked ReasonCode = "bulk_action_blocked"
)

func IsBulkAllowed

func IsBulkAllowed(items []InboxItem) (bool, ReasonCode)

IsBulkAllowed 判断给定 items 是否可以批量操作。 冲突、破坏性 rewrite、cross-scope promotion 和高风险项禁止 bulk approval。

type RiskLevel

type RiskLevel string

RiskLevel 是 inbox item 的风险分级。

const (
	RiskLow    RiskLevel = "low"
	RiskMedium RiskLevel = "medium"
	RiskHigh   RiskLevel = "high"
)

type SourceCoverage

type SourceCoverage struct {
	Total    int `json:"total"`
	Resolved int `json:"resolved"`
	Missing  int `json:"missing"`
	Stale    int `json:"stale"`
}

SourceCoverage 描述来源解析情况(与 agentcontinuity 相同语义,独立定义避免包依赖)。

type SuggestedAction

type SuggestedAction string

SuggestedAction 是 inbox item 建议的下一步操作。

const (
	ActionReview    SuggestedAction = "review"
	ActionApprove   SuggestedAction = "approve"
	ActionReject    SuggestedAction = "reject"
	ActionSupersede SuggestedAction = "supersede"
	ActionExpire    SuggestedAction = "expire"
	ActionRestore   SuggestedAction = "restore"
	ActionInspect   SuggestedAction = "inspect"
)

Jump to

Keyboard shortcuts

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