render.gno
2.89 Kb · 87 lines
1package gnosage
2
3import (
4 "strings"
5
6 "gno.land/p/nt/ufmt/v0"
7)
8
9// Render serves the review board through gnoweb.
10//
11// - Render("") lists every reviewed realm with its latest agent score.
12// - Render("<pkgPath>") shows the review history of one realm, e.g.
13// Render("gno.land/r/<addr>/foo").
14//
15// Caller-controlled text (verdicts) is flattened before rendering so a
16// review can never break the board's markdown layout or smuggle links.
17func Render(path string) string {
18 if path != "" && VersionCount(path) > 0 {
19 return renderDetail(path)
20 }
21 return renderIndex()
22}
23
24// renderIndex lists reviewed realms with their latest agent verdict.
25func renderIndex() string {
26 var b strings.Builder
27 b.WriteString("# GnoSage review board\n\n")
28 b.WriteString("Autonomous AI reviews of Gno realms. Scores are 0-100; the headline score is the latest review by a registered agent reviewer.\n\n")
29 paths := ReviewedPaths()
30 if len(paths) == 0 {
31 b.WriteString("No reviews yet. The agent posts its first verdicts shortly after deploy.\n")
32 return b.String()
33 }
34 b.WriteString("| Realm | Score | Docs | Tests | Safety | Quality | Reviews |\n")
35 b.WriteString("|---|---|---|---|---|---|---|\n")
36 for _, p := range paths {
37 latest := LatestAgentReview(p)
38 if latest == nil {
39 b.WriteString(ufmt.Sprintf("| %s | — | — | — | — | — | %d |\n", p, VersionCount(p)))
40 continue
41 }
42 b.WriteString(ufmt.Sprintf("| [%s](%s) | %d | %d | %d | %d | %d | %d |\n",
43 p, p, latest.Score, latest.Docs, latest.Tests, latest.Safety, latest.Quality, VersionCount(p)))
44 }
45 b.WriteString(ufmt.Sprintf("\n%d review(s) on the board.\n", ReviewCount()))
46 return b.String()
47}
48
49// renderDetail shows every review of one realm, newest first.
50func renderDetail(pkgPath string) string {
51 var b strings.Builder
52 b.WriteString(ufmt.Sprintf("# %s\n\n", pkgPath))
53 latest := LatestAgentReview(pkgPath)
54 if latest != nil {
55 b.WriteString(ufmt.Sprintf("Latest agent verdict (v%d, score %d/100): %s\n\n",
56 latest.Version, latest.Score, flatten(latest.Verdict)))
57 }
58 b.WriteString("## Reviews\n\n")
59 count := VersionCount(pkgPath)
60 for v := count; v >= 1; v-- {
61 r := GetReview(pkgPath, uint64(v))
62 if r == nil {
63 continue
64 }
65 kind := "human"
66 if r.Agent {
67 kind = "agent"
68 }
69 b.WriteString(ufmt.Sprintf("### v%d — %d/100 (%s, %s)\n\n", r.Version, r.Score, kind, r.Reviewer.String()))
70 b.WriteString(ufmt.Sprintf("Docs %d · Tests %d · Safety %d · Quality %d\n\n", r.Docs, r.Tests, r.Safety, r.Quality))
71 b.WriteString(flatten(r.Verdict) + "\n\n")
72 if r.Checks != "" {
73 b.WriteString("Checks: `" + flatten(r.Checks) + "`\n\n")
74 }
75 }
76 return b.String()
77}
78
79// flatten removes markdown-breaking characters from caller text.
80func flatten(s string) string {
81 s = strings.ReplaceAll(s, "\n", " ")
82 s = strings.ReplaceAll(s, "\r", " ")
83 s = strings.ReplaceAll(s, "|", "/")
84 s = strings.ReplaceAll(s, "[", "(")
85 s = strings.ReplaceAll(s, "]", ")")
86 return s
87}