feat(memory): sensitive 标记 + 提取器敏感判据,私事退出受限车道召回
M63(M60 审计 P0-1/P0-2)。作用域 ≠ 敏感度:`scope='user'` 是共享域,里 面却装着住址(花溪 64 条 active)/私称(叶酱 63)/作息(早睡 38),于是受限车 道(群聊/陌生人)把共享域整锅注入上下文 —— 2026-10-29 群 531082168 的住址泄漏 即此路径。本片给 memory_items 加 `sensitive` 列,把「这条归谁」(scope)与 「这条能不能外说」(sensitive)拆成两根正交的轴。 - 迁移 0028:加列(INTEGER NOT NULL DEFAULT 0)+ **同迁移幂等回填**(精确短语 白名单 花溪/叶酱/早睡,`AND sensitive=0`,不改 updated_at),down 只撤结构; memory 包内 `ensureSensitiveSchema` 同形前滚(任意 *sql.DB 自举)。 - 受限判据:新增 `MemoryItem.SharedVisible()` = 共享域 且 !sensitive,成为 restricted 侧唯一起点;`loop.FilterSharedVisible` 与复用它的 knowledge 工具 自动跟随。主人车道不过这道判据,照常读到全部记忆(sensitive 不是权限系统)。 - 提取器:prompt 追加 sensitive 位(住址/私人称呼/家人/健康/作息与行程 → true, 口味/兴趣/项目约定 → false,含正反例);产出侧与落库侧共用 `resolveSensitive`(模型的类目判断 ∨ 已实证短语白名单),只加标不撤标。 - 回填入口 `BackfillSensitive(ctx, db, dryRun)`:幂等、可 dry-run、返回候选池 前后规模与逐短语计数(生产快照实测 3116 → 2948,标 725 行)。 - 读路径并到 15 列(scanItem + 7 处 SELECT);store.go 拆分 store_insert.go 守住 500 行上限。 验收:go build/vet/test 全绿(memory + loop 单包复跑绿);删实现三处变异分别打红 (sensitiveColumn 恒 0 / SharedVisible 忽略 Sensitive / Extractor 跳过白名单); 生产库快照上跑 0028 后 Go 侧回填 marked=0(迁移 SQL 与 privateFacts 等价)。
This commit is contained in:
1 parent
a8bc2b4470
commit
44fbd29836
22 files changed
+1360
-102
No files matched your search
@@ -148,14 +148,17 @@ func TestMigration0027ShapeMatchesStoreBootstrap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
bootCols := tableColumns(t, bootstrapped, "memory_items")
|
||||
if len(bootCols) < 2 {
|
||||
t.Fatalf("自举建的 memory_items 列数 = %d, want ≥ 2", len(bootCols))
|
||||
if len(bootCols) < 3 {
|
||||
t.Fatalf("自举建的 memory_items 列数 = %d, want ≥ 3", len(bootCols))
|
||||
}
|
||||
tail := bootCols[len(bootCols)-2:]
|
||||
// 0028(`sensitive`)之后尾序是 `… retention_tier, temporal, sensitive`:
|
||||
// 新列一律追加在末尾,因此这条断言的「末尾」也随迁移推进(见 store_schema.go 头注)。
|
||||
tail := bootCols[len(bootCols)-3:]
|
||||
if !strings.Contains(tail[0], "|"+retentionTierColumn+"|") ||
|
||||
!strings.Contains(tail[1], "|"+temporalColumn+"|") {
|
||||
t.Fatalf("自举建的 memory_items 尾两列 = %v, want …, %s, %s",
|
||||
tail, retentionTierColumn, temporalColumn)
|
||||
!strings.Contains(tail[1], "|"+temporalColumn+"|") ||
|
||||
!strings.Contains(tail[2], "|"+sensitiveColumn+"|") {
|
||||
t.Fatalf("自举建的 memory_items 尾三列 = %v, want …, %s, %s, %s",
|
||||
tail, retentionTierColumn, temporalColumn, sensitiveColumn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user