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

@ -36,7 +36,7 @@ func Dispatch(h api.BuiltinToolHandlers, tc api.ToolCall, turnScenes []string) (
switch {
case tc.Name == "persona_set":
return h.ExecutePersonaTool(tc), true
case strings.HasPrefix(tc.Name, "memory_"):
case strings.HasPrefix(tc.Name, "stablemem_"):
return h.ExecuteMemoryTool(tc, turnScenes), true
case strings.HasPrefix(tc.Name, "social_"):
return h.ExecuteSocialTool(tc), true
@ -72,21 +72,13 @@ func Dispatch(h api.BuiltinToolHandlers, tc api.ToolCall, turnScenes []string) (
return "", false
}
// IsBuiltinTool 报告某名字是否会由 Dispatch 处理(供诊断与提示词使用)。
// ★ 已删除 IsBuiltinTool(2026-10-29)。
//
// ★ 与 Dispatch 共用同一套前缀常量,避免"两套语义"(历史上出现过
// "模型看得到但插件查不到"的漂移)。
func IsBuiltinTool(name string) bool {
switch {
case name == "persona_set", name == "output_list_channels", name == "input_channels",
name == "resident_agents", name == "notify_parent", name == "inputch_note",
name == "plgreload", name == "get_plugin_tools":
return true
}
for _, p := range []string{"memory_", "social_", "knowledge_", "coldcontext_", "doc_", "secret_", "output_send__"} {
if strings.HasPrefix(name, p) {
return true
}
}
return false
}
// 它曾是 Dispatch 之外**第二份**前缀表,注释还写着"与 Dispatch 共用同一套
// 前缀常量" —— 但实际上是手抄的平行清单,两处都要人肉同步。
// 实测:全仓零调用方(唯一的 device.IsBuiltinTool 包装器同样零调用),
// 却在改名时制造了真实故障:改了 Dispatch 的 stablemem_,漏了这份表,
// 于是"看起来在维护事实来源"的代码变成了误导。
//
// 需要判"某名字会不会被处理"时,**直接调 Dispatch** —— 它的
// (string, bool) 第二个返回值就是权威答案。别再引入平行表。