feat: 段页式记忆流转、coldcontext 重命名与安全治理

记忆层:
- MemoryBlock 承载 FrameTS/PageSeq/PageKind/BlockRole/CallID
- coldcontext 归档与回填按完整页传递,工具调用参数和配对键不丢失
- 召回先估算总 token,超预算时按全局页相似度标记 inactive
- inactive 仅是 context 渲染期状态,不落盘、不进入 coldcontext,Prune 后重置
- Peek/确认/Remove 两阶段召回,失败保留冷上下文副本
- stablemem 记录 last_recalled_at,删块连带清理边

命名:
- internal/memory/document → internal/memory/coldcontext
- Doc/DocEvent/DocHit → ColdDoc/ColdEvent/ColdHit
- ContextToColdContext/RecentColdContexts/FindColdContexts
- 保留既有 JSON 标签、doc_ 文件前缀与 doc_count 状态键,兼容存量数据

安全治理:
- 工具策略门禁、安全配置、事件总线发布者身份与入站脱敏
- 声明式 SecurityAPI 与 QQ owner/guest profile
- 日志保留策略与相关 e2e/回归判据

验证:go build ./...、go vet ./...、go test ./...(62 包);
生产副本 e2e:7013 块迁移后 ID/向量/指纹 0 变化、0 缺失。
This commit is contained in:
JianFeeeee
2026-10-29 23:53:48 +08:00
parent a3e50b395f
commit b850feaef2
113 changed files with 6512 additions and 790 deletions

View File

@ -154,7 +154,7 @@ type Store struct {
// dense 是多模态稠密空间(可选)。与 vectorizer 是**两层不同的东西**:
// vectorizer 把文本变成稀疏特征(TF-IDF/词向量),供**退化路径**使用;
// dense 把 text/image 投到同一个稠密坐标系,让「按图搜知识」
// 「按文搜含图知识」成立。文档记忆(docStore)走的就是后者。
// 「按文搜含图知识」成立。文档记忆(coldcontextStore)走的就是后者。
//
// 为何不把稠密向量塞进 s.vec:vector.Store 是稀疏倒排结构
// (feature → {docID: weight}),稠密向量会把倒排表退化成全量特征桶,
@ -230,7 +230,7 @@ func (s *Store) denseEnabled() bool {
//
// 只有与当前空间**同指纹且同维度**的媒体向量才参与融合。只比指纹不够:
// 指纹相同但维度不同的向量会被 FuseVectors 按最大维度拼成错维度结果,
// 而它下次又被当成"已对齐",就永远错下去(docStore 里踩过同一个坑)。
// 而它下次又被当成"已对齐",就永远错下去(coldcontextStore 里踩过同一个坑)。
//
// 返回 nil 表示本条目在当前空间下无向量(检索侧会跳过它)。
func (s *Store) denseFor(k *Knowledge) []float64 {
@ -302,7 +302,7 @@ func (s *Store) ReindexDense() (built, skipped int) {
built++
}
// 落盘,否则磁盘缓存永远对不上当前空间,判定条件永远成立 ——
// 每次启动都重算同一批(docStore 的 BuildDenseIndex 踩过这个坑)。
// 每次启动都重算同一批(coldcontextStore 的 BuildDenseIndex 踩过这个坑)。
if built > 0 {
s.denseDirty = true
}
@ -1237,7 +1237,7 @@ func shortFP(fp string) string {
// flushDenseLocked 把脏的稠密缓存落盘(调用方须持写锁)。
//
// 为何在 Add 当场落盘而不是等 Stop:进程可能被 kill -9,那时没有任何
// 优雅关停钩子可跑,这批向量的计算就白费了(docStore 的 BuildDenseIndex
// 优雅关停钩子可跑,这批向量的计算就白费了(coldcontextStore 的 BuildDenseIndex
// 出于同样理由选择当场写盘)。
func (s *Store) flushDenseLocked() error {
if !s.denseDirty {