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>
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package store
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"keel/internal/mode/focus/domain"
|
|
)
|
|
|
|
func TestLoadMissingFileReturnsLocked(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "state.json")
|
|
s, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if s.RuntimeState != domain.RuntimeLocked {
|
|
t.Errorf("missing file should be Locked, got %s", s.RuntimeState)
|
|
}
|
|
if s.Commitment != nil {
|
|
t.Errorf("missing file should have nil commitment")
|
|
}
|
|
}
|
|
|
|
func TestSaveThenLoadRoundTrips(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "nested", "state.json")
|
|
c, _ := domain.NewManual("Port store", "store tests pass", 25*time.Minute)
|
|
c.State = domain.CommitmentActive
|
|
want := Snapshot{
|
|
RuntimeState: domain.RuntimeActive,
|
|
Commitment: &c,
|
|
DeadlineUnixSecs: 1748725200,
|
|
}
|
|
if err := Save(path, want); err != nil {
|
|
t.Fatalf("save failed: %v", err)
|
|
}
|
|
got, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("load failed: %v", err)
|
|
}
|
|
if got.RuntimeState != want.RuntimeState {
|
|
t.Errorf("runtime state: got %s want %s", got.RuntimeState, want.RuntimeState)
|
|
}
|
|
if got.Commitment == nil || got.Commitment.NextAction != "Port store" {
|
|
t.Errorf("commitment did not round-trip: %+v", got.Commitment)
|
|
}
|
|
if got.DeadlineUnixSecs != want.DeadlineUnixSecs {
|
|
t.Errorf("deadline: got %d want %d", got.DeadlineUnixSecs, want.DeadlineUnixSecs)
|
|
}
|
|
}
|
|
|
|
func TestSnapshotCarriesSessionFields(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "state.json")
|
|
want := Snapshot{
|
|
RuntimeState: domain.RuntimeActive,
|
|
SessionID: "session-abc",
|
|
OutcomePending: "completed",
|
|
}
|
|
if err := Save(path, want); err != nil {
|
|
t.Fatalf("save: %v", err)
|
|
}
|
|
got, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("load: %v", err)
|
|
}
|
|
if got.SessionID != "session-abc" || got.OutcomePending != "completed" {
|
|
t.Fatalf("session fields did not round-trip: %+v", got)
|
|
}
|
|
}
|