feat: L0 线协议冻结 + 附件链路修复 + 人/Agent 区分
L0 核心: - 严格解码 Decode(DisallowUnknownFields) 全覆盖 29 个 DecodeBody 调用点 - DecodeLenient 心跳专用:容忍新字段但回报 unknown_fields - 400 消息列出本端点接受的全部字段(jsonFieldNames 反射 tag) - 日历 status 校验(create 补字段 + update 拦非法值) - 新增 strictdecode_test.go 10 例 + blob/list_test.go 6 例 A-4 附件挂载回滚:checkAttachable 在 CreateMail 前校验,失败按 解挂→释放 relay→删邮件→退预算回滚,幽灵邮件这条路堵住了 A-5 反向 GC:blob.Store.List() 枚举磁盘(跳 .upload-*), SweepUnreferencedBlobs 按 attachments + calendar_attachments 反查, 48h 年龄下限兜上传窗口。已接进每小时 sweep 循环 C 人/Agent 区分:四个读路径 + threadCols 补 from_human / to_human (EXISTS users 判定),models.Mail 加 ToHuman。前端判据从 workspace 启发式改成显式布尔,mailCounterpart/sessionCounterpart 从 session_workspace 取 path(修 dsh@dsh 拼接 bug) 契约文档:SSE new_mail 补 4 字段(in_reply_to/from_human/ permission_mode/permission_enforcement),B-5 加 B-5.6 (Agent→Agent 不转发),B-3.4 MUST 改条件式,心跳补 mode_enforcement + unknown_fields,demo 死链修复 + from_human 检查 验收清单加 Agent→Agent 负向对照项
This commit is contained in:
@ -16,9 +16,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Store 是附件的磁盘存储。
|
||||
@ -133,6 +135,46 @@ func (s *Store) Exists(sum string) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// List 枚举库中全部内容文件的 sha256 与修改时间。
|
||||
//
|
||||
// # 为什么需要它
|
||||
//
|
||||
// 附件 GC 原先只从**库记录**出发(`WHERE mail_id IS NULL`),于是一旦记录本身
|
||||
// 消失(清库、手工 DELETE、迁移),对应文件就永远脱离了视野:本机实测磁盘 8 个
|
||||
// blob 里 7 个没有任何库记录,全部来自 09-03 那次清库,之后一直占着盘。
|
||||
//
|
||||
// 反向清理必须能枚举磁盘,因此这个方法是 `repo.SweepUnreferencedBlobs` 的前提。
|
||||
//
|
||||
// 只认文件名是合法 sha256 的项:`.upload-*` 临时文件不属于内容库,
|
||||
// 把它们报给调用方会让 GC 去删一个正在写入的文件。
|
||||
func (s *Store) List() (map[string]time.Time, error) {
|
||||
out := map[string]time.Time{}
|
||||
err := filepath.WalkDir(s.root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
// 单个子目录读不了不该让整次枚举失败 —— 但**根目录**读不了必须报:
|
||||
// 那时返回空 map 会让调用方以为「库里什么都没有」,
|
||||
// 于是把仍被引用的文件当成孤儿(这里不会删,但计数会骗人)。
|
||||
if path == s.root {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if d.IsDir() || !sha256Re.MatchString(d.Name()) {
|
||||
return nil // .upload-* 临时文件与其他异物
|
||||
}
|
||||
info, iErr := d.Info()
|
||||
if iErr != nil {
|
||||
return nil
|
||||
}
|
||||
out[d.Name()] = info.ModTime()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("blob: 枚举 %s: %w", s.root, err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Remove 删除某内容。
|
||||
//
|
||||
// 注意:内容寻址意味着多条附件记录可能指向同一个文件,
|
||||
|
||||
Reference in New Issue
Block a user