110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
// 织忆·确定性判据扫描(t_2515307a 取证)——按 namespace 分批扫全表,输出 drop/demote 明细供 AC4
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/xiaoxue/memoryweave/internal/distill"
|
|
)
|
|
|
|
func apikey() string {
|
|
b, _ := os.ReadFile("/var/lib/memoryweave/.api-key")
|
|
for _, l := range strings.Split(string(b), "\n") {
|
|
s := strings.TrimSpace(l)
|
|
if s != "" && !strings.HasPrefix(s, "#") && !strings.Contains(s, "legacy") {
|
|
return strings.Fields(s)[0]
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func list(ns string, limit int) ([]struct {
|
|
ID string `json:"id"`
|
|
Content string `json:"content"`
|
|
}, error) {
|
|
u := fmt.Sprintf("http://127.0.0.1:7821/api/v1/memories?limit=%d", limit)
|
|
if ns != "" {
|
|
u += "&namespace=" + ns
|
|
}
|
|
req, _ := http.NewRequest("GET", u, nil)
|
|
req.Header.Set("X-API-Key", apikey())
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
raw, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<26))
|
|
var d struct {
|
|
Memories []struct {
|
|
ID string `json:"id"`
|
|
Content string `json:"content"`
|
|
} `json:"memories"`
|
|
}
|
|
if err := json.Unmarshal(raw, &d); err != nil {
|
|
return nil, err
|
|
}
|
|
return d.Memories, nil
|
|
}
|
|
|
|
func main() {
|
|
namespaces := []string{
|
|
"", "hermes-main", "shared", "wiki-curator-main", "wiki", "soulful-xiaowei",
|
|
"a06-main", "domain:dev", "default-main", "hermes", "wiki:decision",
|
|
}
|
|
seen := map[string]bool{}
|
|
var all []struct {
|
|
ID string `json:"id"`
|
|
Content string `json:"content"`
|
|
}
|
|
for _, ns := range namespaces {
|
|
ms, err := list(ns, 1000)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
for _, m := range ms {
|
|
if !seen[m.ID] {
|
|
seen[m.ID] = true
|
|
all = append(all, m)
|
|
}
|
|
}
|
|
}
|
|
type rec struct {
|
|
ID string
|
|
Content string
|
|
Why string
|
|
}
|
|
var drops, demotes []rec
|
|
for _, m := range all {
|
|
v, why := distill.RecallRuleVerdict(m.Content)
|
|
if v == distill.RecallDrop {
|
|
drops = append(drops, rec{m.ID, m.Content, why})
|
|
} else if v == distill.RecallDemote {
|
|
demotes = append(demotes, rec{m.ID, m.Content, why})
|
|
}
|
|
}
|
|
fmt.Printf("unique_total=%d drops=%d demotes=%d\n\n", len(all), len(drops), len(demotes))
|
|
fmt.Println("===== DROPS (进不了 top-N) =====")
|
|
for i, d := range drops {
|
|
rc := []rune(d.Content)
|
|
c := d.Content
|
|
if len(rc) > 55 {
|
|
c = string(rc[:55]) + "…"
|
|
}
|
|
fmt.Printf("%2d. [%s] %s\n", i+1, d.Why, c)
|
|
}
|
|
fmt.Println("\n===== DEMOTES (降权) =====")
|
|
for i, d := range demotes {
|
|
rc := []rune(d.Content)
|
|
c := d.Content
|
|
if len(rc) > 55 {
|
|
c = string(rc[:55]) + "…"
|
|
}
|
|
fmt.Printf("%2d. [%s] %s\n", i+1, d.Why, c)
|
|
}
|
|
}
|