package app import ( "fmt" "html" "net/http" "strings" "time" "git.warky.dev/wdevs/amcs/internal/auth" "git.warky.dev/wdevs/amcs/internal/buildinfo" ) const connectedWindow = 10 * time.Minute type statusPageData struct { Version string BuildDate string Commit string ConnectedCount int TotalKnown int Entries []auth.AccessSnapshot OAuthEnabled bool } func renderHomePage(info buildinfo.Info, tracker *auth.AccessTracker, oauthEnabled bool, now time.Time) string { entries := tracker.Snapshot() data := statusPageData{ Version: fallback(info.Version, "dev"), BuildDate: fallback(info.BuildDate, "unknown"), Commit: fallback(info.Commit, "unknown"), ConnectedCount: tracker.ConnectedCount(now, connectedWindow), TotalKnown: len(entries), Entries: entries, OAuthEnabled: oauthEnabled, } var b strings.Builder b.WriteString(` AMCS
Avelon Memory Crystal project image

Avelon Memory Crystal Server (AMCS)

AMCS is a memory server that captures, links, and retrieves structured project thoughts for AI assistants using semantic search, summaries, and MCP tools.

LLM Instructions Health Check Readiness Check`) if data.OAuthEnabled { b.WriteString(` OAuth Authorization Server`) } b.WriteString(`
Connected users ` + fmt.Sprintf("%d", data.ConnectedCount) + `
Known principals ` + fmt.Sprintf("%d", data.TotalKnown) + `
Version ` + html.EscapeString(data.Version) + `
Build date: ` + html.EscapeString(data.BuildDate) + `  •  Commit: ` + html.EscapeString(data.Commit) + `  •  Connected window: last 10 minutes

Recent access

`) if len(data.Entries) == 0 { b.WriteString(`

No authenticated access recorded yet.

`) } else { b.WriteString(` `) for _, entry := range data.Entries { b.WriteString(` `) } b.WriteString(`
Principal Last accessed Last path Requests
` + html.EscapeString(entry.KeyID) + ` ` + html.EscapeString(entry.LastAccessedAt.UTC().Format(time.RFC3339)) + ` ` + html.EscapeString(entry.LastPath) + ` ` + fmt.Sprintf("%d", entry.RequestCount) + `
`) } b.WriteString(`
`) return b.String() } func fallback(value, defaultValue string) string { if strings.TrimSpace(value) == "" { return defaultValue } return value } func homeHandler(info buildinfo.Info, tracker *auth.AccessTracker, oauthEnabled bool) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) return } if r.Method != http.MethodGet && r.Method != http.MethodHead { w.Header().Set("Allow", "GET, HEAD") http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) if r.Method == http.MethodHead { return } _, _ = w.Write([]byte(renderHomePage(info, tracker, oauthEnabled, time.Now()))) } }