feat(divergence): Jev noul restatement check -> harness review nudge (#25)

This commit is contained in:
Smokey committed 2026-10-28 05:37:19 -06:00
1 parent b04aace26b
commit dfe50da320
3 files changed
+121

No files matched your search

+40
View File
@@ -184,6 +184,10 @@ func (s *Server) postNestMessage(w http.ResponseWriter, r *http.Request) {
}
}
if kind == "deliver" {
go s.checkDivergence(nest, record)
}
writeJSON(w, http.StatusCreated, nestRecord(record))
}
@@ -298,6 +302,42 @@ func (s *Server) respondOne(nest Nest, req Message, crow string, lens bool) {
}
if record, err := s.msgs.Append(reply); err == nil {
s.emitNestMessage(record)
if record.Kind == "deliver" {
s.checkDivergence(nest, record)
}
}
}
// checkDivergence asks Jev whether this deliver restates earlier delivers that
// answer the same request. Above the band the crow gets a review nudge; the
// deliver itself stays in the log (nudges never silence).
func (s *Server) checkDivergence(nest Nest, m Message, budgets ...*Budget) {
if m.Kind != "deliver" {
return
}
earlier := s.msgs.EarlierDelivers(nest.ID, m.RefersTo, m.ID)
if len(earlier) == 0 {
return
}
if _, nudged := s.msgs.NudgeFor(nest.ID, m.MsgID()); nudged {
return // one nudge per deliver; no loop
}
prob, ok := s.p.Flock.ClassifyDivergence(s.ctx, map[string]any{"this": m.Text, "earlier": earlier}, budgets...)
if !ok || prob < s.p.Flock.jev.threshold {
return
}
nudge := Message{
NestID: nest.ID,
Kind: "nudge",
Author: "harness",
Text: "This reads like a point already made in the thread; review the earlier delivers and add your distinct angle or let it rest.",
To: m.Author,
RefersTo: m.MsgID(),
TaggedBy: "harness",
Timestamp: time.Now().UTC().Format(time.RFC3339),
}
if record, err := s.msgs.Append(nudge); err == nil {
s.emitNestMessage(record)
}
}