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

@ -0,0 +1,69 @@
package proc
// 安全策略**声明面**的宿主侧实现(插件子进程 → 内核)。
//
// ## 为什么在 proc 包而不是让插件直连 security
//
// 插件是**子进程**,它唯一的通道就是本桥(stdio JSON-RPC + 共享内存)。
// 它拿不到 security.Runtime,也不该拿到 —— 那会让插件能直接改策略表。
//
// 而判定点必须在这里还有第二个原因:**Owner 要由内核填**。
// 插件自报的 owner 可以伪造(任何插件都能声明 `qq.owner` 并给
// AllowTools=["*"],等于把 QQ 的 owner 档位改成全放行),
// 所以本包用 `h.sdk.PluginName()`(内核侧真实标识)作为 owner,
// 而不是采信参数里的值。
//
// ## 与 internal/sdk/security_impl.go 的关系
//
// 那里的 `securityImpl` 才是真正的实现(含 owner 校验与 Runtime 转发)。
// 本文件只做 JSON 解码 → 调它 → 把错误带回去,保持与其他
// corehandler_* 分部函数同构。
import (
"encoding/json"
"fmt"
pubsdk "github.com/JianFeeeee/hologramagentsdk/sdk"
)
func (h *coreHandler) handleSecurity(method string, params json.RawMessage) (interface{}, error) {
api := h.sdk.Security()
if api == nil {
// 未装配(独立工具/特殊宿主)时明确报错,而不是静默成功:
// 静默成功会让插件以为档位已登记,直到注入时才暴露。
return nil, fmt.Errorf("security: the declaration API is not wired in this host")
}
switch method {
case MethodSecurityDeclareProfile:
var p struct {
Profile pubsdk.SecurityProfile `json:"profile"`
}
if err := unmarshal(params, &p); err != nil {
return nil, err
}
if err := api.DeclareProfile(p.Profile); err != nil {
return nil, err
}
return map[string]interface{}{"ok": true, "name": p.Profile.Name}, nil
case MethodSecurityDeclareProfiles:
var p struct {
Profiles []pubsdk.SecurityProfile `json:"profiles"`
}
if err := unmarshal(params, &p); err != nil {
return nil, err
}
if err := api.DeclareProfiles(p.Profiles); err != nil {
return nil, err
}
names := make([]string, len(p.Profiles))
for i, pr := range p.Profiles {
names[i] = pr.Name
}
return map[string]interface{}{"ok": true, "names": names}, nil
}
// 组内不应到达:Handle 的分派表与 case 标签同源。
return nil, fmt.Errorf("未知 method: %s", method)
}