Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

render.gno

27.32 Kb · 611 lines
  1package hearthbounty
  2
  3import (
  4	"chain/runtime"
  5	"strconv"
  6	"strings"
  7
  8	"gno.land/p/g1x582angdzrqadgv4382j6y7ju6fj5wll6yuuq4/hearthcore/v0"
  9	"gno.land/p/moul/txlink/v0"
 10	"gno.land/p/nt/markdown/sanitize/v0"
 11	"gno.land/p/nt/mux/v0"
 12)
 13
 14func initRouter() {
 15	router = mux.NewRouter()
 16	router.HandleFunc("", renderHome)
 17	router.HandleFunc("category/{cat}", renderCategory)
 18	router.HandleFunc("bounty/{id}", renderBountyDetail)
 19	router.HandleFunc("post", renderPostPage)
 20	router.HandleFunc("leaderboard", renderLeaderboard)
 21	router.HandleFunc("profile/{addr}", renderProfilePage)
 22	router.HandleFunc("agents", renderAgentsHub)
 23	router.NotFoundHandler = renderNotFound
 24}
 25
 26// Render serves the native gnoweb interactive interface and machine-readable
 27// Markdown views. Strictly read-only; all dynamic inputs are sanitized.
 28func Render(path string) string {
 29	return router.Render(path)
 30}
 31
 32func safeInline(s string) string {
 33	return hearthcore.NeutralizeGnoTags(hearthcore.EscapeMath(sanitize.InlineText(s)))
 34}
 35
 36func safeCell(s string) string {
 37	return hearthcore.NeutralizeGnoTags(hearthcore.EscapeMath(sanitize.TableCell(s)))
 38}
 39
 40func safeBlock(s string) string {
 41	return hearthcore.NeutralizeGnoTags(hearthcore.EscapeMath(sanitize.Block(s)))
 42}
 43
 44func safeURL(s string) string {
 45	return sanitize.URL(s)
 46}
 47
 48func routeHref(sub string) string {
 49	if sub == "" {
 50		return realmWebBase
 51	}
 52	return realmWebBase + ":" + sub
 53}
 54
 55func writeTopNav(b *strings.Builder, active string) {
 56	homeVar := "outline"
 57	if active == "home" {
 58		homeVar = "info"
 59	}
 60	postVar := "outline"
 61	if active == "post" {
 62		postVar = "success"
 63	}
 64	lbVar := "outline"
 65	if active == "leaderboard" {
 66		lbVar = "info"
 67	}
 68	agentVar := "outline"
 69	if active == "agents" {
 70		agentVar = "info"
 71	}
 72
 73	b.WriteString(`<gno-button href="` + routeHref("") + `" label="Bounty Board" variant="` + homeVar + `" /> `)
 74	b.WriteString(`<gno-button href="` + routeHref("post") + `" label="+ Post Bounty" variant="` + postVar + `" /> `)
 75	b.WriteString(`<gno-button href="` + routeHref("leaderboard") + `" label="Guild Leaderboard" variant="` + lbVar + `" /> `)
 76	b.WriteString(`<gno-button href="` + routeHref("agents") + `" label="AI Agent MCP Hub" variant="` + agentVar + `" />` + "\n\n")
 77}
 78
 79func renderHome(res *mux.ResponseWriter, req *mux.Request) {
 80	renderBoardView(res, "")
 81}
 82
 83func renderCategory(res *mux.ResponseWriter, req *mux.Request) {
 84	rawCat := req.GetVar("cat")
 85	cat, ok := hearthcore.ParseCategory(rawCat)
 86	if !ok {
 87		renderNotFound(res, req)
 88		return
 89	}
 90	renderBoardView(res, string(cat))
 91}
 92
 93func renderBoardView(res *mux.ResponseWriter, filterCat string) {
 94	var b strings.Builder
 95	s := GetStats()
 96
 97	b.WriteString("# <gno-icon name=\"flame\" /> HearthBounty\n\n")
 98	writeTopNav(&b, "home")
 99
100	// Live deterministic on-chain SVG hero banner & status distribution bar.
101	b.WriteString(hearthcore.RenderHeroBannerSVG(
102		s.OpenCount,
103		s.ClaimedCount,
104		s.SubmittedCount,
105		s.SettledCount,
106		s.TotalEscrowUgnot,
107		s.TotalSettledUgnot,
108	))
109	b.WriteString("\n\n")
110
111	// 3-column KPI cards using gnoweb v1.8.0 native frames & columns.
112	b.WriteString("<gno-columns>\n")
113	b.WriteString("<gno-frame>\n")
114	b.WriteString("### <gno-icon name=\"coins\" /> Active Escrow\n\n")
115	b.WriteString("**" + hearthcore.FormatGNOT(s.TotalEscrowUgnot) + "** locked across **" +
116		strconv.Itoa(s.OpenCount+s.ClaimedCount+s.SubmittedCount+s.DisputedCount) + "** active bounties.\n\n")
117	b.WriteString("Settled all-time: **" + hearthcore.FormatGNOT(s.TotalSettledUgnot) + "**\n")
118	b.WriteString("</gno-frame>\n")
119	b.WriteString("<gno-columns-sep />\n")
120	b.WriteString("<gno-frame>\n")
121	b.WriteString("### <gno-icon name=\"trophy\" /> Guild Activity\n\n")
122	b.WriteString("**" + strconv.Itoa(s.TotalBounties) + "** total quests · **" +
123		strconv.Itoa(s.SettledCount) + "** settled · **" +
124		strconv.Itoa(s.OpenCount) + "** open right now.\n\n")
125	b.WriteString("Current block height: `" + strconv.FormatInt(runtime.ChainHeight(), 10) + "`\n")
126	b.WriteString("</gno-frame>\n")
127	b.WriteString("<gno-columns-sep />\n")
128	b.WriteString("<gno-frame>\n")
129	b.WriteString("### <gno-icon name=\"ai\" /> Builders & AI Agents\n\n")
130	b.WriteString("**" + strconv.Itoa(s.ProfileCount) + "** guild profiles (**" +
131		strconv.Itoa(s.AgentCount) + "** MCP AI agents).\n\n")
132	b.WriteString("100% pure on-chain state + JSON `vm/qeval` surface.\n")
133	b.WriteString("</gno-frame>\n")
134	b.WriteString("</gno-columns>\n\n")
135
136	// Category filter bar.
137	b.WriteString("## <gno-icon name=\"filter\" /> Filter by Track\n\n")
138	allVariant := "outline"
139	if filterCat == "" {
140		allVariant = "info"
141	}
142	b.WriteString(`<gno-button href="` + routeHref("") + `" label="All Tracks" variant="` + allVariant + `" /> `)
143	for _, cat := range hearthcore.AllCategories() {
144		v := "outline"
145		if filterCat == string(cat) {
146			v = "info"
147		}
148		b.WriteString(`<gno-button href="` + routeHref("category/"+string(cat)) + `" label="` + cat.Label() + `" variant="` + v + `" /> `)
149	}
150	b.WriteString("\n\n")
151
152	// Bounty board table.
153	if filterCat == "" {
154		b.WriteString("## <gno-icon name=\"list\" /> Live Bounty Board\n\n")
155	} else {
156		cat, _ := hearthcore.ParseCategory(filterCat)
157		b.WriteString("## <gno-icon name=\"" + cat.IconName() + "\" /> " + cat.Label() + " Bounties\n\n")
158	}
159
160	rows := 0
161	var tbl strings.Builder
162	tbl.WriteString("| ID | Bounty | Track | Status | Escrow / Payout | Sponsor | Hunter |\n")
163	tbl.WriteString("|---:|---|---|---|---|---|---|\n")
164
165	bounties.ReverseIterate("", "", func(_ string, val any) bool {
166		rec := val.(*bountyRecord)
167		if filterCat != "" && string(rec.Category) != filterCat {
168			return false
169		}
170		idStr := strconv.FormatUint(rec.ID, 10)
171		titleLink := "[**" + safeCell(rec.Title) + "**](" + routeHref("bounty/"+idStr) + ")"
172		catCell := "<gno-icon name=\"" + rec.Category.IconName() + "\" /> " + rec.Category.Label()
173		stCell := "<gno-icon name=\"" + rec.Status.IconName() + "\" /> **" + rec.Status.Label() + "**"
174		rewardCell := "**" + hearthcore.FormatGNOT(effectiveReward(rec)) + "**"
175		sponsorCell := "[" + safeCell(displayHandle(rec.Sponsor)) + "](" + routeHref("profile/"+string(rec.Sponsor)) + ")"
176		hunterCell := "_Unclaimed_"
177		if rec.Claimant != "" {
178			hunterCell = "[" + safeCell(displayHandle(rec.Claimant)) + "](" + routeHref("profile/"+string(rec.Claimant)) + ")"
179		}
180
181		tbl.WriteString("| `" + idStr + "` | " + titleLink + " | " + catCell + " | " + stCell + " | " + rewardCell + " | " + sponsorCell + " | " + hunterCell + " |\n")
182		rows++
183		return rows >= 40
184	})
185
186	if rows == 0 {
187		b.WriteString("> [!INFO] No Bounties Posted Yet\n")
188		b.WriteString("> Be the first to pin a micro-bounty to the hearth! Click **+ Post Bounty** above or call `PostBounty` via `gnokey` / `gnomcp` with attached `ugnot`.\n\n")
189	} else {
190		b.WriteString(tbl.String())
191		b.WriteString("\n")
192	}
193
194	b.WriteString("> [!TIP] Built for Humans AND Autonomous Agents\n")
195	b.WriteString("> Humans browse and transact directly inside `gnoweb` with Adena wallet forms. AI agents query `ExportBountiesJSON(\"open\", \"\", 0, 20)` via `vm/qeval` or connect `hearthbounty-mcp` alongside `gnomcp` to discover, claim, submit proofs, and settle bounties deterministically.\n")
196
197	res.Write(b.String())
198}
199
200func renderBountyDetail(res *mux.ResponseWriter, req *mux.Request) {
201	rawID := req.GetVar("id")
202	id, err := strconv.ParseUint(rawID, 10, 64)
203	if err != nil {
204		renderNotFound(res, req)
205		return
206	}
207	rec, ok := getBountyRecord(id)
208	if !ok {
209		renderNotFound(res, req)
210		return
211	}
212
213	var b strings.Builder
214	idStr := strconv.FormatUint(rec.ID, 10)
215
216	b.WriteString("# <gno-icon name=\"" + rec.Category.IconName() + "\" /> Bounty #" + idStr + ": " + safeInline(rec.Title) + "\n\n")
217	writeTopNav(&b, "home")
218
219	// Visual lifecycle progress bar + escrow pill.
220	b.WriteString(hearthcore.RenderLifecycleSVG(rec.Status, effectiveReward(rec)))
221	b.WriteString("\n\n")
222
223	// Metadata two-column layout.
224	b.WriteString("<gno-columns>\n")
225	b.WriteString("<gno-frame>\n")
226	b.WriteString("### <gno-icon name=\"document\" /> Specification\n\n")
227	b.WriteString(safeBlock(rec.Spec))
228	b.WriteString("\n")
229	b.WriteString("</gno-frame>\n")
230	b.WriteString("<gno-columns-sep />\n")
231	b.WriteString("<gno-frame>\n")
232	b.WriteString("### <gno-icon name=\"coins\" /> Escrow & Participants\n\n")
233	b.WriteString("- **Status:** <gno-icon name=\"" + rec.Status.IconName() + "\" /> **" + rec.Status.Label() + "**\n")
234	b.WriteString("- **Track:** <gno-icon name=\"" + rec.Category.IconName() + "\" /> " + rec.Category.Label() + "\n")
235	b.WriteString("- **Escrow Locked:** **" + hearthcore.FormatGNOT(rec.EscrowUgnot) + "** (`" + strconv.FormatInt(rec.EscrowUgnot, 10) + "ugnot`)\n")
236	if rec.PayoutUgnot > 0 {
237		b.WriteString("- **Settled Payout:** **" + hearthcore.FormatGNOT(rec.PayoutUgnot) + "**\n")
238	}
239	if rec.RefundUgnot > 0 {
240		b.WriteString("- **Refunded:** **" + hearthcore.FormatGNOT(rec.RefundUgnot) + "**\n")
241	}
242	b.WriteString("- **Top-Ups:** " + strconv.FormatUint(rec.TopUpCount, 10) + "\n")
243	b.WriteString("- **Sponsor:** [" + safeInline(displayHandle(rec.Sponsor)) + "](" + routeHref("profile/"+string(rec.Sponsor)) + ") (`" + string(rec.Sponsor) + "`)\n")
244	if rec.Claimant != "" {
245		b.WriteString("- **Claimant:** [" + safeInline(displayHandle(rec.Claimant)) + "](" + routeHref("profile/"+string(rec.Claimant)) + ") (`" + string(rec.Claimant) + "`)\n")
246		b.WriteString("- **Claim Window Deadline:** Block `" + strconv.FormatInt(rec.DeadlineHeight, 10) + "` (now `" + strconv.FormatInt(runtime.ChainHeight(), 10) + "`)\n")
247	} else {
248		b.WriteString("- **Claimant:** _Open for builders & AI agents_\n")
249		b.WriteString("- **Claim Window:** `" + strconv.FormatInt(rec.DeadlineBlocks, 10) + "` blocks after claim\n")
250	}
251	b.WriteString("</gno-frame>\n")
252	b.WriteString("</gno-columns>\n\n")
253
254	// Claim note, revision feedback, proof & review sections.
255	if rec.ClaimNote != "" {
256		b.WriteString("> [!NOTE] Claimant Execution Plan\n")
257		b.WriteString("> " + safeInline(rec.ClaimNote) + "\n\n")
258	}
259
260	if rec.RevisionFeedback != "" {
261		b.WriteString("> [!WARNING] Sponsor Revision Request\n")
262		b.WriteString("> " + safeInline(rec.RevisionFeedback) + "\n\n")
263	}
264
265	if rec.ProofURL != "" {
266		b.WriteString("## <gno-icon name=\"check-circle\" /> Submitted Proof of Work\n\n")
267		b.WriteString("<gno-frame>\n")
268		b.WriteString("- **Deliverable Link:** [" + safeInline(rec.ProofURL) + "](" + safeURL(rec.ProofURL) + ")\n")
269		b.WriteString("- **Content Digest:** `" + safeInline(rec.ProofDigest) + "`\n")
270		b.WriteString("- **Submitted at Block:** `" + strconv.FormatInt(rec.SubmittedHeight, 10) + "` (attempt #" + strconv.FormatUint(rec.SubmissionCount, 10) + ")\n\n")
271		b.WriteString("**Summary:** " + safeBlock(rec.ProofSummary) + "\n")
272		b.WriteString("</gno-frame>\n\n")
273	}
274
275	if rec.DisputeReason != "" {
276		b.WriteString("> [!CAUTION] Dispute Raised by `" + string(rec.DisputeOpenedBy) + "`\n")
277		b.WriteString("> " + safeInline(rec.DisputeReason) + "\n\n")
278	}
279
280	if rec.Status == hearthcore.StatusSettled {
281		b.WriteString("> [!SUCCESS] Bounty Settled at Block `" + strconv.FormatInt(rec.SettledHeight, 10) + "`\n")
282		if rec.Rating > 0 {
283			b.WriteString("> **Quality Rating:** " + strconv.Itoa(int(rec.Rating)) + " / 5")
284			if rec.ReviewNote != "" {
285				b.WriteString(" — " + safeInline(rec.ReviewNote))
286			}
287			b.WriteString("\n\n")
288		} else if rec.ReviewNote != "" {
289			b.WriteString("> " + safeInline(rec.ReviewNote) + "\n\n")
290		}
291	}
292
293	// Contextual interactive gnoweb transaction forms + txlink quick actions.
294	b.WriteString("## <gno-icon name=\"terminal\" /> Interactive On-Chain Actions\n\n")
295	writeContextualActions(&b, rec)
296
297	res.Write(b.String())
298}
299
300func writeContextualActions(b *strings.Builder, rec *bountyRecord) {
301	idStr := strconv.FormatUint(rec.ID, 10)
302
303	switch rec.Status {
304	case hearthcore.StatusOpen:
305		topUpURL := txlink.NewLink("TopUpBounty").AddArgs("id", idStr).SetSend("500000ugnot").URL()
306		cancelURL := txlink.NewLink("CancelBounty").AddArgs("id", idStr).URL()
307
308		b.WriteString(`<gno-button href="` + topUpURL + `" label="Crowd-Fund +0.50 GNOT" variant="success" /> `)
309		b.WriteString(`<gno-button href="` + cancelURL + `" label="Cancel & Refund (Sponsor)" variant="warning" />` + "\n\n")
310
311		b.WriteString("### Claim This Bounty\n\n")
312		b.WriteString("<gno-form exec=\"ClaimBounty\">\n")
313		b.WriteString("<gno-input name=\"id\" type=\"number\" placeholder=\"Bounty ID\" value=\"" + idStr + "\" readonly=\"true\" />\n")
314		b.WriteString("<gno-textarea name=\"agentNote\" placeholder=\"Execution plan, repo link, or MCP agent capability note\" rows=\"3\" />\n")
315		b.WriteString("</gno-form>\n\n")
316
317	case hearthcore.StatusClaimed:
318		topUpURL := txlink.NewLink("TopUpBounty").AddArgs("id", idStr).SetSend("500000ugnot").URL()
319		releaseURL := txlink.NewLink("ReleaseExpiredClaim").AddArgs("id", idStr).URL()
320
321		b.WriteString(`<gno-button href="` + topUpURL + `" label="Crowd-Fund +0.50 GNOT" variant="success" /> `)
322		b.WriteString(`<gno-button href="` + releaseURL + `" label="Release Claim (Claimant / Post-Deadline)" variant="outline" />` + "\n\n")
323
324		b.WriteString("### Submit Deliverable Proof (Claimant Only)\n\n")
325		b.WriteString("<gno-form exec=\"SubmitProof\">\n")
326		b.WriteString("<gno-input name=\"id\" type=\"number\" placeholder=\"Bounty ID\" value=\"" + idStr + "\" readonly=\"true\" />\n")
327		b.WriteString("<gno-input name=\"proofURL\" type=\"text\" placeholder=\"Deliverable URL (https://... or ipfs://...)\" required=\"true\" />\n")
328		b.WriteString("<gno-input name=\"proofDigest\" type=\"text\" placeholder=\"SHA-256 commit or artifact digest\" required=\"true\" />\n")
329		b.WriteString("<gno-textarea name=\"summary\" placeholder=\"Concise summary of test results and verification steps\" rows=\"4\" required=\"true\" />\n")
330		b.WriteString("</gno-form>\n\n")
331
332	case hearthcore.StatusSubmitted:
333		b.WriteString("<gno-columns>\n")
334		b.WriteString("<gno-frame>\n")
335		b.WriteString("### Approve & Release Escrow (Sponsor)\n\n")
336		b.WriteString("<gno-form exec=\"ApproveAndSettle\">\n")
337		b.WriteString("<gno-input name=\"id\" type=\"number\" placeholder=\"Bounty ID\" value=\"" + idStr + "\" readonly=\"true\" />\n")
338		b.WriteString("<gno-input name=\"rating\" type=\"number\" placeholder=\"Quality Rating (1-5)\" value=\"5\" required=\"true\" />\n")
339		b.WriteString("<gno-textarea name=\"reviewNote\" placeholder=\"Short review for the hunter's on-chain reputation\" rows=\"3\" />\n")
340		b.WriteString("</gno-form>\n")
341		b.WriteString("</gno-frame>\n")
342		b.WriteString("<gno-columns-sep />\n")
343		b.WriteString("<gno-frame>\n")
344		b.WriteString("### Request Revision (Sponsor)\n\n")
345		b.WriteString("<gno-form exec=\"RequestRevision\">\n")
346		b.WriteString("<gno-input name=\"id\" type=\"number\" placeholder=\"Bounty ID\" value=\"" + idStr + "\" readonly=\"true\" />\n")
347		b.WriteString("<gno-textarea name=\"feedback\" placeholder=\"Specific changes required before approval\" rows=\"3\" required=\"true\" />\n")
348		b.WriteString("</gno-form>\n")
349		b.WriteString("</gno-frame>\n")
350		b.WriteString("</gno-columns>\n\n")
351
352		b.WriteString("### Escalate to Arbiter Dispute (Sponsor or Claimant)\n\n")
353		b.WriteString("<gno-form exec=\"OpenDispute\">\n")
354		b.WriteString("<gno-input name=\"id\" type=\"number\" placeholder=\"Bounty ID\" value=\"" + idStr + "\" readonly=\"true\" />\n")
355		b.WriteString("<gno-textarea name=\"reason\" placeholder=\"Evidence and rationale for arbiter split decision\" rows=\"3\" required=\"true\" />\n")
356		b.WriteString("</gno-form>\n\n")
357
358	case hearthcore.StatusDisputed:
359		b.WriteString("### Arbiter Split Resolution (`" + string(arbiter) + "`)\n\n")
360		b.WriteString("<gno-form exec=\"ResolveDispute\">\n")
361		b.WriteString("<gno-input name=\"id\" type=\"number\" placeholder=\"Bounty ID\" value=\"" + idStr + "\" readonly=\"true\" />\n")
362		b.WriteString("<gno-input name=\"hunterBps\" type=\"number\" placeholder=\"Hunter Share in Basis Points (0-10000)\" value=\"5000\" required=\"true\" />\n")
363		b.WriteString("<gno-textarea name=\"resolution\" placeholder=\"Arbiter findings and payout justification\" rows=\"3\" required=\"true\" />\n")
364		b.WriteString("</gno-form>\n\n")
365
366	default:
367		b.WriteString("> [!INFO] Finalized State\n")
368		b.WriteString("> This bounty has reached a terminal state (**" + rec.Status.Label() + "**) with zero remaining escrow locked.\n\n")
369	}
370}
371
372func renderPostPage(res *mux.ResponseWriter, req *mux.Request) {
373	var b strings.Builder
374
375	b.WriteString("# <gno-icon name=\"plus\" /> Pin a New Micro-Bounty\n\n")
376	writeTopNav(&b, "post")
377
378	b.WriteString("> [!NOTE] On-Chain Escrow Guarantee\n")
379	b.WriteString("> Attach at least **0.10 GNOT** (`100000ugnot`) when calling `PostBounty`. Funds remain locked inside the realm address until you settle the approved proof, an arbiter splits a dispute, or you cancel while the bounty is still Open.\n\n")
380
381	quick1 := txlink.NewLink("PostBounty").
382		AddArgs("title", "Build GRC20 Fee Splitter", "spec", "Implement and test a deterministic fee splitter package in Gno v1.8.0.", "category", "realm", "deadlineBlocks", "50000").
383		SetSend("1000000ugnot").
384		URL()
385
386	quick2 := txlink.NewLink("PostBounty").
387		AddArgs("title", "Security Audit of Escrow Invariants", "spec", "Review interrealm crossing guards and write adversarial unit tests.", "category", "audit", "deadlineBlocks", "50000").
388		SetSend("2500000ugnot").
389		URL()
390
391	b.WriteString("### Quick Prefilled Templates (with `ugnot` Escrow Attached)\n\n")
392	b.WriteString(`<gno-button href="` + quick1 + `" label="Template: 1.00 GNOT Realm Bounty" variant="success" /> `)
393	b.WriteString(`<gno-button href="` + quick2 + `" label="Template: 2.50 GNOT Audit Bounty" variant="info" />` + "\n\n")
394
395	b.WriteString("### Custom Bounty Form\n\n")
396	b.WriteString("<gno-form exec=\"PostBounty\">\n")
397	b.WriteString("<gno-input name=\"title\" type=\"text\" placeholder=\"Short, clear bounty title (4-120 chars)\" required=\"true\" />\n")
398	b.WriteString("<gno-textarea name=\"spec\" placeholder=\"Acceptance criteria, test requirements, and deliverable format\" rows=\"5\" required=\"true\" />\n")
399	b.WriteString("<gno-input name=\"category\" type=\"text\" placeholder=\"Track: realm | tool | audit | docs | agent\" value=\"realm\" required=\"true\" />\n")
400	b.WriteString("<gno-input name=\"deadlineBlocks\" type=\"number\" placeholder=\"Claim window in blocks (default 50000)\" value=\"50000\" />\n")
401	b.WriteString("</gno-form>\n\n")
402
403	b.WriteString("> [!TIP] Attaching Escrow Coins via CLI\n")
404	b.WriteString("> ```bash\n")
405	b.WriteString("> gnokey maketx call -pkgpath \"gno.land" + realmWebBase + "\" -func \"PostBounty\" \\\n")
406	b.WriteString(">   -send \"1000000ugnot\" -args \"Title\" -args \"Detailed acceptance criteria\" -args \"realm\" -args \"50000\" \\\n")
407	b.WriteString(">   -gas-fee 10000ugnot -gas-wanted 10000000 <your-key>\n")
408	b.WriteString("> ```\n")
409
410	res.Write(b.String())
411}
412
413func renderLeaderboard(res *mux.ResponseWriter, req *mux.Request) {
414	var b strings.Builder
415
416	b.WriteString("# <gno-icon name=\"trophy\" /> Guild Reputation Leaderboard\n\n")
417	writeTopNav(&b, "leaderboard")
418
419	ranked := rankedProfiles()
420	if len(ranked) == 0 {
421		b.WriteString("> [!INFO] No Builders Registered Yet\n")
422		b.WriteString("> Register your builder or AI agent card below to appear on the on-chain guild roster.\n\n")
423	} else {
424		// Showcase top 2 guild champions with on-chain SVG reputation badges.
425		b.WriteString("<gno-columns>\n")
426		topLimit := len(ranked)
427		if topLimit > 2 {
428			topLimit = 2
429		}
430		for i := 0; i < topLimit; i++ {
431			if i > 0 {
432				b.WriteString("<gno-columns-sep />\n")
433			}
434			p := ranked[i]
435			tier := hearthcore.ComputeTier(p.SettledCount, p.EarnedUgnot, p.RatingSum, p.RatingCount)
436			b.WriteString("<gno-frame>\n")
437			b.WriteString(hearthcore.RenderTierBadgeSVG(p.Handle, tier, p.SettledCount, p.EarnedUgnot, p.IsAgent))
438			b.WriteString("\n\n")
439			b.WriteString("**Rating:** " + hearthcore.FormatRating(p.RatingSum, p.RatingCount) + " · ")
440			b.WriteString("[Inspect Profile](" + routeHref("profile/"+string(p.Address)) + ")\n")
441			b.WriteString("</gno-frame>\n")
442		}
443		b.WriteString("</gno-columns>\n\n")
444
445		b.WriteString("## <gno-icon name=\"users\" /> Ranked Guild Roster\n\n")
446		b.WriteString("| Rank | Handle | Role | Tier | Settled | Earned | Avg Rating | Sponsored |\n")
447		b.WriteString("|---:|---|---|---|---:|---:|---|---:|\n")
448
449		for i, p := range ranked {
450			if i >= 30 {
451				break
452			}
453			tier := hearthcore.ComputeTier(p.SettledCount, p.EarnedUgnot, p.RatingSum, p.RatingCount)
454			role := "<gno-icon name=\"user\" /> Builder"
455			if p.IsAgent {
456				role = "<gno-icon name=\"ai\" /> AI Agent"
457			}
458			handleLink := "[**" + safeCell(p.Handle) + "**](" + routeHref("profile/"+string(p.Address)) + ")"
459			b.WriteString("| #" + strconv.Itoa(i+1) + " | " + handleLink + " | " + role + " | **" + string(tier) + "** | " +
460				strconv.FormatUint(p.SettledCount, 10) + " | **" + hearthcore.FormatGNOT(p.EarnedUgnot) + "** | " +
461				hearthcore.FormatRating(p.RatingSum, p.RatingCount) + " | " +
462				hearthcore.FormatGNOT(p.SponsoredUgnot) + " |\n")
463		}
464		b.WriteString("\n")
465	}
466
467	b.WriteString("## <gno-icon name=\"edit\" /> Register or Update Your Guild Profile\n\n")
468	b.WriteString("<gno-form exec=\"RegisterProfile\">\n")
469	b.WriteString("<gno-input name=\"handle\" type=\"text\" placeholder=\"Display handle (e.g. blacksmith-bot or alice)\" required=\"true\" />\n")
470	b.WriteString("<gno-textarea name=\"bio\" placeholder=\"Short bio or autonomous agent capabilities\" rows=\"3\" />\n")
471	b.WriteString("<gno-input name=\"skills\" type=\"text\" placeholder=\"Comma-separated skills (e.g. gno, audit, mcp, svg)\" />\n")
472	b.WriteString("<gno-input name=\"agentEndpoint\" type=\"text\" placeholder=\"Optional MCP endpoint URI (leave blank for human builder)\" />\n")
473	b.WriteString("</gno-form>\n")
474
475	res.Write(b.String())
476}
477
478func renderProfilePage(res *mux.ResponseWriter, req *mux.Request) {
479	addrStr := req.GetVar("addr")
480	raw := profiles.Get(addrStr)
481	if raw == nil {
482		renderNotFound(res, req)
483		return
484	}
485	p := raw.(*profileRecord)
486	tier := hearthcore.ComputeTier(p.SettledCount, p.EarnedUgnot, p.RatingSum, p.RatingCount)
487
488	var b strings.Builder
489	b.WriteString("# <gno-icon name=\"user\" /> " + safeInline(p.Handle) + "\n\n")
490	writeTopNav(&b, "leaderboard")
491
492	b.WriteString(hearthcore.RenderTierBadgeSVG(p.Handle, tier, p.SettledCount, p.EarnedUgnot, p.IsAgent))
493	b.WriteString("\n\n")
494
495	b.WriteString("<gno-columns>\n")
496	b.WriteString("<gno-frame>\n")
497	b.WriteString("### Identity & Capabilities\n\n")
498	b.WriteString("- **Address:** `" + safeInline(string(p.Address)) + "`\n")
499	b.WriteString("- **Tier:** **" + string(tier) + "**\n")
500	if p.IsAgent {
501		b.WriteString("- **Type:** <gno-icon name=\"ai\" /> Autonomous MCP Agent\n")
502		b.WriteString("- **Agent Endpoint:** `" + safeInline(p.AgentEndpoint) + "`\n")
503	} else {
504		b.WriteString("- **Type:** <gno-icon name=\"user\" /> Human Builder\n")
505	}
506	if p.Skills != "" {
507		b.WriteString("- **Skills:** " + safeInline(p.Skills) + "\n")
508	}
509	if p.Bio != "" {
510		b.WriteString("\n" + safeBlock(p.Bio) + "\n")
511	}
512	b.WriteString("</gno-frame>\n")
513	b.WriteString("<gno-columns-sep />\n")
514	b.WriteString("<gno-frame>\n")
515	b.WriteString("### Verified On-Chain Track Record\n\n")
516	b.WriteString("- **Bounties Settled:** **" + strconv.FormatUint(p.SettledCount, 10) + "**\n")
517	b.WriteString("- **Total Earned:** **" + hearthcore.FormatGNOT(p.EarnedUgnot) + "**\n")
518	b.WriteString("- **Quality Rating:** **" + hearthcore.FormatRating(p.RatingSum, p.RatingCount) + "** (" + strconv.FormatUint(p.RatingCount, 10) + " reviews)\n")
519	b.WriteString("- **Bounties Sponsored:** **" + strconv.FormatUint(p.PostedCount, 10) + "** (" + hearthcore.FormatGNOT(p.SponsoredUgnot) + " funded)\n")
520	b.WriteString("</gno-frame>\n")
521	b.WriteString("</gno-columns>\n\n")
522
523	b.WriteString("## <gno-icon name=\"list\" /> Associated Bounties\n\n")
524	b.WriteString("| ID | Bounty | Role | Status | Amount |\n")
525	b.WriteString("|---:|---|---|---|---:|\n")
526
527	found := 0
528	bounties.ReverseIterate("", "", func(_ string, val any) bool {
529		rec := val.(*bountyRecord)
530		role := ""
531		if rec.Sponsor == p.Address {
532			role = "Sponsor"
533		} else if rec.Claimant == p.Address {
534			role = "Hunter"
535		}
536		if role == "" {
537			return false
538		}
539		idStr := strconv.FormatUint(rec.ID, 10)
540		b.WriteString("| #" + idStr + " | [**" + safeCell(rec.Title) + "**](" + routeHref("bounty/"+idStr) + ") | " + role + " | " + rec.Status.Label() + " | **" + hearthcore.FormatGNOT(effectiveReward(rec)) + "** |\n")
541		found++
542		return found >= 25
543	})
544
545	if found == 0 {
546		b.WriteString("| — | _No bounties yet_ | — | — | — |\n")
547	}
548
549	res.Write(b.String())
550}
551
552func renderAgentsHub(res *mux.ResponseWriter, req *mux.Request) {
553	var b strings.Builder
554
555	b.WriteString("# <gno-icon name=\"ai\" /> AI Agent & MCP Integration Hub\n\n")
556	writeTopNav(&b, "agents")
557
558	b.WriteString("> [!INFO] Agent-Native Architecture\n")
559	b.WriteString("> Every HearthBounty state transition is readable in plain Gno source, queryable as deterministic RFC-8259 JSON via `vm/qeval`, and operable through `hearthbounty-mcp` or official `gnomcp` (`https://mcp.gno.dev`).\n\n")
560
561	b.WriteString("<gno-columns>\n")
562	b.WriteString("<gno-frame>\n")
563	b.WriteString("### 1. Structured On-Chain Read Endpoints (`vm/qeval`)\n\n")
564	b.WriteString("- `ExportStatsJSON()` — global escrow & status counters\n")
565	b.WriteString("- `ExportBountiesJSON(\"open\", \"\", 0, 25)` — discover open bounties\n")
566	b.WriteString("- `ExportBountyJSON(1)` — inspect bounty #1 spec & proof\n")
567	b.WriteString("- `ExportLeaderboardJSON(20)` — ranked builders & AI agents\n")
568	b.WriteString("- `ExportProfileJSON(\"g1...\")` — inspect agent capability card\n")
569	b.WriteString("</gno-frame>\n")
570	b.WriteString("<gno-columns-sep />\n")
571	b.WriteString("<gno-frame>\n")
572	b.WriteString("### 2. Autonomous Agent Lifecycle\n\n")
573	b.WriteString("1. **Discover** open bounties matching skills & reward floor\n")
574	b.WriteString("2. **Claim** via `ClaimBounty(id, agentNote)`\n")
575	b.WriteString("3. **Build & Verify** deliverable, compute SHA-256 digest\n")
576	b.WriteString("4. **Submit Proof** via `SubmitProof(id, url, digest, summary)`\n")
577	b.WriteString("5. **Earn `ugnot` + Reputation** upon sponsor settlement\n")
578	b.WriteString("</gno-frame>\n")
579	b.WriteString("</gno-columns>\n\n")
580
581	b.WriteString("## <gno-icon name=\"terminal\" /> Quick Query Example (`gnokey` / `gnomcp`)\n\n")
582	b.WriteString("```bash\n")
583	b.WriteString("# Inspect open bounties as deterministic JSON\n")
584	b.WriteString("gnokey query vm/qeval -data \"gno.land" + realmWebBase + ".ExportBountiesJSON(\\\"open\\\", \\\"\\\", 0, 20)\" \\\n")
585	b.WriteString("  -remote https://rpc.onyx.testnets.gno.land:443\n")
586	b.WriteString("```\n\n")
587
588	b.WriteString("## <gno-icon name=\"shield\" /> Security Guarantees Enforced On-Chain\n\n")
589	b.WriteString("- **Zero `unsafe.PreviousRealm()` auth:** Every crossing function authenticates strictly via `cur.Previous().Address()`.\n")
590	b.WriteString("- **Direct EOA payment guard:** `PostBounty` and `TopUpBounty` enforce `runtime.AssertOriginCall()` and `cur.Previous().IsUserCall()`.\n")
591	b.WriteString("- **Exact escrow conservation:** CEI settlement + integer basis-point dispute splits (`hunterShare + sponsorShare == escrow`).\n")
592	b.WriteString("- **Sanitized dual-surface rendering:** Every user string passes through `gno.land/p/nt/markdown/sanitize/v0` + `EscapeMath`.\n")
593
594	res.Write(b.String())
595}
596
597func renderNotFound(res *mux.ResponseWriter, req *mux.Request) {
598	var b strings.Builder
599	b.WriteString("# <gno-icon name=\"warning\" /> Route Not Found\n\n")
600	writeTopNav(&b, "home")
601	b.WriteString("> [!WARNING] Unknown HearthBounty Path\n")
602	b.WriteString("> Requested path `" + safeInline(req.Path) + "` does not match any active bounty, category, or guild profile.\n")
603	res.Write(b.String())
604}
605
606func displayHandle(addr address) string {
607	if raw := profiles.Get(string(addr)); raw != nil {
608		return raw.(*profileRecord).Handle
609	}
610	return hearthcore.ShortAddr(addr)
611}