// Command memdump reads a dendrite memory database and prints its contents. package main import ( "fmt" "os" "git.mleku.dev/mleku/dendrite/pkg/memory" ) func main() { dir := "_output/inst0/memory" if len(os.Args) > 1 { dir = os.Args[1] } db, err := memory.Open(dir) if err != nil { fmt.Fprintf(os.Stderr, "open: %v\n", err) os.Exit(1) } defer db.Close() fmt.Printf("=== Memory DB: %s ===\n\n", dir) // Generation metadata. fmt.Println("--- Generations ---") for gen := uint32(0); gen < 20; gen++ { meta := db.QueryGeneration(gen) if meta == nil { break } fmt.Printf(" gen %d: parent=%q inst=%d\n", gen, meta.ParentHash, meta.InstanceID) } // Fitness trajectory. fmt.Println("\n--- Fitness Trajectory ---") traj := db.QueryFitnessTrajectory(20) for _, p := range traj { fmt.Printf(" gen %d: %d/%d (%.4f)\n", p.Gen, p.Score.Num, p.Score.Denom, p.Score.Float64()) } // Fitness dimensions. dims := []struct { name string dim byte }{ {"source", memory.DimSource}, {"binary", memory.DimBinary}, {"behav", memory.DimBehav}, } for _, d := range dims { pts := db.QueryFitnessDimension(d.dim, 20) if len(pts) > 0 { fmt.Printf("\n--- Fitness: %s ---\n", d.name) for _, p := range pts { fmt.Printf(" gen %d: %.4f\n", p.Gen, p.Score.Float64()) } } } // Health history. fmt.Println("\n--- Health ---") health := db.QueryHealthHistory(20) for _, h := range health { fmt.Printf(" gen %d: %d/%d occupied (%.1f%%), avg-lockin=%.3f\n", h.Gen, h.Occupied, h.Total, float64(h.Occupied)/float64(h.Total)*100, h.AvgLockIn.Float64()) } // Type signature trends (top tags). tags := []string{"func", "type", "ident", "literal", "assign", "if", "return", "for", "import", "field"} fmt.Println("\n--- Type Trends ---") for _, tag := range tags { trend := db.QueryTypeTrend(tag, 20) if len(trend) == 0 { continue } fmt.Printf(" %s:", tag) for _, p := range trend { fmt.Printf(" gen%d=%d", p.Gen, p.Count) } fmt.Println() } // Bond history. fmt.Println("\n--- Bond History ---") for _, tag := range tags { hist := db.QueryBondHistory(tag, 20) if len(hist) == 0 { continue } fmt.Printf(" %s:", tag) for _, p := range hist { fmt.Printf(" gen%d=%d", p.Gen, p.Count) } fmt.Println() } // Missing trends. fmt.Println("\n--- Missing Sites ---") for _, tag := range tags { miss := db.QueryMissingTrend(tag, 20) if len(miss) == 0 { continue } fmt.Printf(" %s:", tag) for _, p := range miss { fmt.Printf(" gen%d=%d", p.Gen, p.Count) } fmt.Println() } // Hexagram operations (OpNone=0, OpAccrete=1, ..., OpRecycle=8). opNames := map[byte]string{ 0: "none", 1: "accrete", 2: "dissolve", 3: "nucleate", 4: "prune", 5: "strengthen", 6: "explore", 7: "collapse", 8: "recycle", } fmt.Println("\n--- Hexagram Ops ---") for op := byte(0); op <= 8; op++ { pts := db.QueryHexagramOps(op, 20) if len(pts) == 0 { continue } fmt.Printf(" %s:", opNames[op]) for _, p := range pts { fmt.Printf(" gen%d=%d", p.Gen, p.Count) } fmt.Println() } // Digest: cross-referenced analysis. fmt.Println("\n--- Digest ---") dig := db.WalkDigest(tags, 10) if dig == nil { fmt.Println(" (insufficient data — need 2+ generations)") } else { fmt.Printf(" generations seen: %d\n", dig.GenerationsSeen) fmt.Printf(" occupancy trend: %s\n", dig.OccupancyTrend) fmt.Printf(" fitness trend: %s\n", dig.FitnessTrend) fmt.Printf(" explore ratio: %.1f%%\n", dig.ExploreRatio.Float64()*100) fmt.Printf(" overextended: %v\n", dig.OverExtended) if len(dig.Types) > 0 { fmt.Println(" per-type:") for _, tag := range tags { td, ok := dig.Types[tag] if !ok { continue } fmt.Printf(" %s: bond_rate=%.1f%% missing_delta=%+d\n", td.Tag, td.BondRate.Float64()*100, td.MissingDelta) } } } }