// Package noise holds the shared denylist used to filter low-signal browser // navigation and to deny/refocus knowledge threads seeded by it. The same URL // patterns drive both, so a webapp that is not a knowledge signal also cannot // spawn or pollute a thread. package noise import ( "os" "strings" ) // defaultPatterns are substrings of URLs that represent webapp/account // navigation rather than knowledge signals — logins, mail/calendar/docs apps, // password managers, OAuth flows, and knox's own UI. var defaultPatterns = []string{ "opencode.ai", "auth.opencode.ai", // auth / OAuth / identity "github.com/login/oauth/authorize", "accounts.google.com", "google.com/accounts", "myaccount.google.com", "login.microsoftonline.com", "login.live.com", "appleid.apple.com", "okta.com", "auth0.com", "duosecurity.com", "lastpass.com", "1password.com", "bitwarden.com", "dashlane.com", // Google workspace webapps "mail.google.com", "inbox.google.com", "calendar.google.com", "drive.google.com", "docs.google.com", "sheets.google.com", "slides.google.com", "meet.google.com", // finance / account webapps "privacy.com", "secure.bankofamerica.com", "bankofamerica.com", "moneydesktop.com", "beta-bridge.simplefin.org", // assistant/chat tools "kagi.com", "chatgpt.com", // knox indexing its own web UI is self-referential noise "localhost:8924", "localhost:18925", "127.0.0.1:8924", "127.0.0.1:18925", } // genericLabels are second-level labels too common/legitimate to deny as a // thread topic (e.g. "google" would suppress real Google/Gemini work). var genericLabels = map[string]bool{ "google": true, "live": true, "apple": true, "opencode": true, "github": true, "localhost": true, "googleusercontent": true, } var patterns = BuildPatterns() // BuildPatterns resolves the defaults plus KNOX_BROWSER_DENY (comma-separated), // lowercased. Exposed for tests. func BuildPatterns() []string { out := append([]string{}, defaultPatterns...) for _, p := range strings.Split(os.Getenv("KNOX_BROWSER_DENY"), ",") { if p = strings.ToLower(strings.TrimSpace(p)); p != "" { out = append(out, p) } } return out } // IsNoisyURL reports whether a URL is webapp/account navigation rather than a // knowledge signal. Matching is case-insensitive substring. func IsNoisyURL(url string) bool { u := strings.ToLower(url) for _, p := range patterns { if strings.Contains(u, p) { return true } } return false } // DenyKeywords derives thread-topic deny keywords from the URL patterns (e.g. // "privacy.com" -> "privacy", "host.simplefin.org" -> "simplefin"), skipping // paths/ports/IPs and generic labels. KNOX_THREAD_DENY adds explicit extras. func DenyKeywords() map[string]bool { out := make(map[string]bool) for _, p := range patterns { p = strings.ToLower(strings.TrimSpace(p)) if p == "" || strings.ContainsAny(p, "/:") { continue } labels := strings.Split(p, ".") label := labels[0] if len(labels) >= 2 { label = labels[len(labels)-2] // strip the TLD } label = strings.Trim(label, "-") if len(label) < 3 || genericLabels[label] || isNumeric(label) { continue } out[label] = true } for _, e := range strings.Split(os.Getenv("KNOX_THREAD_DENY"), ",") { if e = strings.ToLower(strings.TrimSpace(e)); e != "" { out[e] = true } } return out } // IsDeniedTopic reports whether a thread title/motivation/tags reference a // denylisted webapp topic. func IsDeniedTopic(text string) bool { return MatchDeniedTopic(text) != "" } // MatchDeniedTopic returns the denylisted keyword a text references, or "" if // none. Useful for explaining why a thread is flagged. func MatchDeniedTopic(text string) string { t := strings.ToLower(text) for k := range DenyKeywords() { if strings.Contains(t, k) { return k } } return "" } func isNumeric(s string) bool { for _, r := range s { if r < '0' || r > '9' { return false } } return len(s) > 0 }