7d69a1f320
Loosen AntiDrift's session controller into Keel's general collect→brain→act
loop. A new internal/harness runs at most one mode.Mode at a time, fanning
async completions out to the web SSE and status-bar surfaces.
- internal/mode: the Mode contract (Kind/Command/View/Active) plus optional
EvidenceConsumer and Expirer ports, and the surfacing Envelope.
- internal/mode/focus: the former session/domain/statemachine packages moved
under the mode, now satisfying the harness contracts unchanged.
- internal/mode/offscreen: a one-shot away-from-desk mode built on the new
ai.Proposer, which turns a life-domain brief into one off-screen action.
- cmd/keeld replaces cmd/antidriftd; daemon wires focus + offscreen factories
with per-mode persistence under ~/.keel/modes/<kind>.
- Finish the rename: KEEL_* env refs in the README, /keeld build artifact
ignored, stale antidriftd binary removed.
Include the design + implementation plan this refactor was built from under
docs/superpowers/{specs,plans}/2026-06-04-controller-refactor*.md.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
package evidence
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"keel/internal/mode/focus/domain"
|
|
)
|
|
|
|
func TestWindowClassMatchesCaseAndTrim(t *testing.T) {
|
|
ctx := domain.AllowedContext{WindowClasses: []string{" code "}}
|
|
if !windowClassAllowed(ctx, " Code ") {
|
|
t.Fatal("class should match case-insensitively after trim")
|
|
}
|
|
if windowClassAllowed(ctx, "firefox") {
|
|
t.Fatal("unrelated class must not match")
|
|
}
|
|
if windowClassAllowed(ctx, " ") {
|
|
t.Fatal("empty candidate must not match")
|
|
}
|
|
}
|
|
|
|
func TestWindowClassMatchesSubstring(t *testing.T) {
|
|
// Users type a short app name ("brave") but the real WM_CLASS is longer
|
|
// ("Brave-browser"). The allowed token matching as a substring of the actual
|
|
// class keeps the local on-task fast path working instead of silently routing
|
|
// every window to the LLM judge.
|
|
ctx := domain.AllowedContext{WindowClasses: []string{"brave"}}
|
|
if !windowClassAllowed(ctx, "Brave-browser") {
|
|
t.Fatal("short allowed token should match the longer real class")
|
|
}
|
|
if windowClassAllowed(ctx, "firefox") {
|
|
t.Fatal("unrelated class must not match")
|
|
}
|
|
}
|
|
|
|
func TestWindowTitleMatchesSubstring(t *testing.T) {
|
|
ctx := domain.AllowedContext{WindowTitleSubstrings: []string{" antidrift "}}
|
|
if !windowTitleAllowed(ctx, "Commitment OS - AntiDrift") {
|
|
t.Fatal("title substring should match after trim/casefold")
|
|
}
|
|
if windowTitleAllowed(ctx, "random video") {
|
|
t.Fatal("unrelated title must not match")
|
|
}
|
|
}
|
|
|
|
func TestDomainMatchesExactAndSubdomain(t *testing.T) {
|
|
ctx := domain.AllowedContext{Domains: []string{" GitHub.COM. "}}
|
|
if !domainAllowed(ctx, "github.com") {
|
|
t.Fatal("exact domain should match")
|
|
}
|
|
if !domainAllowed(ctx, " DOCS.GITHUB.COM. ") {
|
|
t.Fatal("subdomain should match after normalization")
|
|
}
|
|
if domainAllowed(ctx, "evilgithub.com") {
|
|
t.Fatal("suffix-without-dot must not match")
|
|
}
|
|
}
|
|
|
|
func TestCommandMatchesExecutableBasename(t *testing.T) {
|
|
ctx := domain.AllowedContext{Commands: []string{"cargo"}}
|
|
if !commandAllowed(ctx, "/home/felixm/.cargo/bin/cargo test") {
|
|
t.Fatal("basename of full path should match")
|
|
}
|
|
if !commandAllowed(ctx, "cargo") {
|
|
t.Fatal("bare command should match")
|
|
}
|
|
if commandAllowed(ctx, "/usr/bin/git status") {
|
|
t.Fatal("unrelated command must not match")
|
|
}
|
|
}
|
|
|
|
func TestMatchesAllowedClassOrTitle(t *testing.T) {
|
|
ctx := domain.AllowedContext{
|
|
WindowClasses: []string{"code"},
|
|
WindowTitleSubstrings: []string{"antidrift"},
|
|
}
|
|
if !MatchesAllowed(ctx, "Code", "anything") {
|
|
t.Fatal("class match should satisfy MatchesAllowed")
|
|
}
|
|
if !MatchesAllowed(ctx, "firefox", "my AntiDrift tab") {
|
|
t.Fatal("title match should satisfy MatchesAllowed")
|
|
}
|
|
if MatchesAllowed(ctx, "firefox", "youtube") {
|
|
t.Fatal("neither match must be off-task")
|
|
}
|
|
if MatchesAllowed(domain.AllowedContext{}, "code", "antidrift") {
|
|
t.Fatal("empty context matches nothing")
|
|
}
|
|
}
|