M1: evidence types, Source port, ScrubTitle

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 12:35:45 -04:00
parent edca3e280b
commit a31ce702fe
2 changed files with 85 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
// Package evidence is the activity port: a dumb active-window sensor behind a
// Source interface, plus the value types it emits. It makes no judgment about
// whether a window is on-task — that is the advisor's job in a later milestone.
package evidence
import (
"context"
"regexp"
)
// EvidenceHealth records whether the sensor could observe the active window.
type EvidenceHealth struct {
Available bool // true when a window was observed
Reason string // empty when Available; populated when not
}
// WindowSnapshot is one observation of the active window.
type WindowSnapshot struct {
Title string // full _NET_WM_NAME (raw; used in live view + raw log)
Class string // WM_CLASS
Health EvidenceHealth
}
// Source is the activity port. Watch runs until ctx is cancelled, invoking
// onChange on every active-window change, and once immediately with the
// current window.
type Source interface {
Watch(ctx context.Context, onChange func(WindowSnapshot))
}
// titleNoise matches the legacy clock/ratio/percent runs that pollute bucket
// keys (e.g. "1:23", "50.5%", "-3.0"). Ported verbatim from the Rust impl.
var titleNoise = regexp.MustCompile(`-?\d+([:.]\d+)+%?`)
// ScrubTitle removes volatile numeric runs so window titles bucket stably.
// The raw event log keeps the unscrubbed title; only bucket keys are scrubbed.
func ScrubTitle(title string) string {
return titleNoise.ReplaceAllString(title, "")
}