From f8ba396fec9828c927c5ba067a2a5197be9589d2 Mon Sep 17 00:00:00 2001 From: kami Date: Sun, 5 Jul 2026 02:13:13 +0400 Subject: [PATCH] mavweb: add /history page for command history - New /history route displays recent facts in a dedicated page with voided-row styling (line-through + opacity + badge). - Navigation link added to /dash page header. - Handler calls core.RecentFacts(ctx, 200) and renders historyTmpl. --- cmd/mavweb/dash.html | 2 ++ cmd/mavweb/history.html | 33 +++++++++++++++++++++++++++++++++ cmd/mavweb/main.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 cmd/mavweb/history.html diff --git a/cmd/mavweb/dash.html b/cmd/mavweb/dash.html index 594867f..699c9f3 100644 --- a/cmd/mavweb/dash.html +++ b/cmd/mavweb/dash.html @@ -8,7 +8,9 @@ .pending{color:#fc6}.acted{color:#6c6}.ignored{color:#888}.snoozed{color:#c9f} .pres{color:#6c6}.away{color:#888} .updated{color:#666;font-size:.85rem;margin-top:-.5rem;margin-bottom:1rem} + nav a{color:#8cf;margin-right:1rem;font-size:.85rem} +

presence

{{.Presence.Bucket}} — score {{printf "%.2f" .Presence.Score}} ({{ago .Presence.Updated}})

обновляется каждые 10с
diff --git a/cmd/mavweb/history.html b/cmd/mavweb/history.html new file mode 100644 index 0000000..bd39934 --- /dev/null +++ b/cmd/mavweb/history.html @@ -0,0 +1,33 @@ + + + + +maven · history + +

maven · command history

+ +

{{len .Facts}} facts shown (newest first)

+ + +{{range .Facts}} + + + + + + +{{end}} +
whenkindkeyvaluesourceconf
{{if .VoidsID}}⨯ voided{{end}}{{.Ts.Format "2006-01-02 15:04"}}{{.Kind}}{{.Key}}{{.Value}}{{.Source}}{{printf "%.2f" .Confidence}}
diff --git a/cmd/mavweb/main.go b/cmd/mavweb/main.go index a9cd01e..aecc72d 100644 --- a/cmd/mavweb/main.go +++ b/cmd/mavweb/main.go @@ -45,6 +45,9 @@ var staticFiles embed.FS //go:embed dash.html var dashHTML string +//go:embed history.html +var historyHTML string + // dashTmpl — the monitoring read surface, server-rendered from dash.html (no JS, // no client fetch); meta-refresh keeps it live. html/template escapes the user // text in facts/nudges. Read-only: browses the append-only store via CoreAPI, @@ -127,6 +130,9 @@ func main() { mux.HandleFunc("/dash", func(w http.ResponseWriter, r *http.Request) { handleDash(w, r, core) }) + mux.HandleFunc("/history", func(w http.ResponseWriter, r *http.Request) { + handleHistory(w, r, core) + }) // ----- passkey (WebAuthn) endpoints ----- // Wired when both -core and a configured origin are present. The origin // must match the browser's view of mavweb (e.g. https://maven.kvmx.ru). @@ -357,6 +363,28 @@ input[type=text]{width:22rem}code{background:#f4f4f4;padding:.1rem .3rem} {{else}}

none enabled.

{{end}} ` +var historyTmpl = template.Must(template.New("history").Parse(historyHTML)) + +func handleHistory(w http.ResponseWriter, r *http.Request, core ipc.CoreAPI) { + if core == nil { + http.Error(w, "history disabled (no -core)", http.StatusServiceUnavailable) + return + } + ctx := r.Context() + facts, err := core.RecentFacts(ctx, 200) + if err != nil { + log.Printf("history: %v", err) + http.Error(w, "core read failed", http.StatusBadGateway) + return + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + if err := historyTmpl.Execute(w, struct { + Facts []ipc.Fact + }{facts}); err != nil { + log.Printf("history render: %v", err) + } +} + // handleTools serves the enable surface (GET) and applies an enable (POST). // POST fields: name, cmd (space-separated argv), destructive (checkbox). cmd is // whitespace-split — argv with embedded spaces isn't supported (ponytail: no