Files
wangdefa f782b612ec build: 内置 norma 模块,构建不再依赖上游仓库
把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到
third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或
改写 tag 都不再影响本仓库构建。

- 已验证 GOPROXY=off 下可完整编译并打出发行包
- go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希)
- 升级方法与授权注意事项见 third_party/README.md
2026-10-20 21:10:41 -07:00

80 lines
2.1 KiB
Go

package noa
// syncBlocks reconciles block liveness against the messages actually present,
// and prunes the token snapshot down to live refs.
//
// A block goes inactive when it has been absorbed by a higher tier, or when
// neither its covered messages nor its rendered summary are present any more
// (the host trimmed history, or a resume started from a shorter view).
func syncBlocks(io NodeIO, _ PipelineContext) NodeIO {
state := CloneState(io.State)
present := make(map[string]bool, len(io.Messages))
liveRefs := make(map[string]bool, len(io.Messages))
for _, m := range io.Messages {
if m.ID == "" {
continue
}
present[m.ID] = true
if ref, ok := state.MessageRefs.ByRaw[m.ID]; ok && ref != BlockedRef {
liveRefs[ref] = true
}
}
// Snapshot pruning: entries for refs no longer in view are dead weight. The
// length check keeps the common case (nothing changed) allocation-free.
if len(state.TokenSnapshot) != len(liveRefs) {
kept := make(map[string]int, len(liveRefs))
for ref, n := range state.TokenSnapshot {
if liveRefs[ref] {
kept[ref] = n
}
}
state.TokenSnapshot = kept
}
consumed := map[string]bool{}
for _, b := range state.Blocks {
for _, id := range b.DirectBlockIDs {
consumed[id] = true
}
}
for i := range state.Blocks {
b := &state.Blocks[i]
if consumed[b.BlockID] {
// Absorbed by a higher tier; its content now belongs to the parent.
b.Active = false
continue
}
b.Active = blockStillPresent(*b, present)
}
io.State = state
return io
}
// blockStillPresent reports whether a block still stands for something in view:
// any covered message, or its own rendered summary.
func blockStillPresent(b CompressionBlock, present map[string]bool) bool {
if present[SummaryMessageID(b.BlockID)] {
return true
}
for _, id := range b.EffectiveMessageIDs {
if present[id] {
return true
}
}
return false
}
// syncBlocksNode is the pipeline stage wrapper.
func syncBlocksNode() PipelineNode {
return nodeFunc{
name: "sync-blocks",
enabled: func(io NodeIO, _ PipelineContext) bool {
return len(io.State.Blocks) > 0 || len(io.State.TokenSnapshot) > 0
},
run: syncBlocks,
}
}