Implement phase 2.1 (human detection) and 2.2 (notifications): - Detection scorer computes 0.0-1.0 human likelihood from keystroke timing variance, special key usage, typing speed, command diversity, and session duration - Webhook notifier sends JSON POST to configured endpoints with deduplication, custom headers, and event filtering - RecordingChannel gains an event callback for feeding keystrokes to the scorer without coupling shell and detection packages - Server wires scorer into session lifecycle with periodic updates and threshold-based notification triggers - Web UI shows human score in session tables with highlighting - New config sections: [detection] and [[notify.webhooks]] Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
961 B
Go
51 lines
961 B
Go
package web
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
"time"
|
|
)
|
|
|
|
//go:embed templates/*.html templates/fragments/*.html
|
|
var templateFS embed.FS
|
|
|
|
func loadTemplates() (*template.Template, error) {
|
|
funcMap := template.FuncMap{
|
|
"formatTime": func(t time.Time) string {
|
|
return t.Format("2006-01-02 15:04:05 UTC")
|
|
},
|
|
"truncateID": func(id string) string {
|
|
if len(id) > 8 {
|
|
return id[:8]
|
|
}
|
|
return id
|
|
},
|
|
"derefTime": func(t *time.Time) time.Time {
|
|
if t == nil {
|
|
return time.Time{}
|
|
}
|
|
return *t
|
|
},
|
|
"derefFloat": func(f *float64) float64 {
|
|
if f == nil {
|
|
return 0
|
|
}
|
|
return *f
|
|
},
|
|
"formatScore": func(f *float64) string {
|
|
if f == nil {
|
|
return "-"
|
|
}
|
|
return fmt.Sprintf("%.0f%%", *f*100)
|
|
},
|
|
}
|
|
|
|
return template.New("").Funcs(funcMap).ParseFS(templateFS,
|
|
"templates/layout.html",
|
|
"templates/dashboard.html",
|
|
"templates/fragments/stats.html",
|
|
"templates/fragments/active_sessions.html",
|
|
)
|
|
}
|