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
This commit is contained in:
wangdefa committed 2026-10-20 21:10:41 -07:00
1 parent a819fa3230
commit f782b612ec
213 files changed
+37401 -2

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
package noaadapter
import (
"fmt"
"sort"
"strings"
"github.com/Autumn-27/norma/noa"
)
// DeadRangeTracker breaks the loop where a model keeps asking to compress refs
// that cannot resolve.
//
// A small model handed a stale ref will often resubmit the identical batch: the
// rejection tells it the range is dead, but not that repeating it is futile.
// Each retry costs a full turn, and the failure ladder alone is slow to bite
// because a parse-clean call that reclaims nothing still looks like progress.
//
// So the second sighting of the same range set is refused outright, with the
// live ranges named — a rejection the model can act on instead of repeat.
type DeadRangeTracker struct {
// seen counts how many times each range-set signature has failed.
seen map[string]int
}
// NewDeadRangeTracker returns an empty tracker.
func NewDeadRangeTracker() *DeadRangeTracker {
return &DeadRangeTracker{seen: map[string]int{}}
}
// signature identifies a batch by its ranges, order-independent: the model may
// reshuffle a retry without changing what it is asking for.
func signature(ranges []noa.CompressRange) string {
parts := make([]string, 0, len(ranges))
for _, r := range ranges {
parts = append(parts, strings.ToLower(strings.TrimSpace(r.StartRef))+".."+
strings.ToLower(strings.TrimSpace(r.EndRef)))
}
sort.Strings(parts)
return strings.Join(parts, ",")
}
// Check reports whether this batch has already failed often enough to refuse.
// The returned string is the refusal to show the model; "" means proceed.
func (d *DeadRangeTracker) Check(ranges []noa.CompressRange, state noa.CompressionState) string {
if len(ranges) == 0 {
return ""
}
if d.seen[signature(ranges)] < noa.DeadRepeatReject {
return ""
}
var b strings.Builder
fmt.Fprintf(&b, "This exact range set has already failed %d times and will fail again — "+
"the refs do not resolve against the current context. Do not resubmit it.",
noa.DeadRepeatReject)
// Naming what IS live turns a dead end into a next step.
if spans := noa.ActiveBlockSpans(state); len(spans) > 0 {
var live []string
for _, s := range spans {
live = append(live, fmt.Sprintf("%s(T%d)=%s–%s", s.BlockID, s.Tier, s.StartRef, s.EndRef))
}
fmt.Fprintf(&b, "\nLive blocks you can target instead: %s.", strings.Join(live, ", "))
}
b.WriteString("\nOtherwise use the refs shown in the <noa-ref> tags of the current context.")
return b.String()
}
// Record notes that a batch failed.
func (d *DeadRangeTracker) Record(ranges []noa.CompressRange) {
if len(ranges) == 0 {
return
}
d.seen[signature(ranges)]++
}
// Reset clears the tracker after a successful compression: the view changed, so
// what was dead before may not be now.
func (d *DeadRangeTracker) Reset() {
d.seen = map[string]int{}
}