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>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Package harness is the generic host: it owns shared services and exactly one
|
|
// active mode, and routes evidence, expiry, and commands to it.
|
|
package harness
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// Async runs generation-guarded background work for a mode. It preserves the
|
|
// lock discipline of the original session.runFetchAsync: fetch runs with no
|
|
// lock held; stale and apply run under the mode's mutex; notify fires once,
|
|
// after the lock is released.
|
|
type Async struct {
|
|
mu *sync.Mutex
|
|
notify func()
|
|
}
|
|
|
|
// NewAsync binds the helper to a mode's mutex and the harness change-notify.
|
|
func NewAsync(mu *sync.Mutex, notify func()) Async {
|
|
return Async{mu: mu, notify: notify}
|
|
}
|
|
|
|
// Run launches a background fetch. stale returns true to DISCARD the result
|
|
// (a newer generation superseded it). apply records a non-stale result under
|
|
// the mutex and must NOT call notify — Run owns the post-unlock notify.
|
|
func (a Async) Run(timeout time.Duration, fetch func(ctx context.Context), stale func() bool, apply func()) {
|
|
go func() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
defer cancel()
|
|
fetch(ctx)
|
|
a.mu.Lock()
|
|
if stale() {
|
|
a.mu.Unlock()
|
|
return
|
|
}
|
|
apply()
|
|
a.mu.Unlock()
|
|
if a.notify != nil {
|
|
a.notify()
|
|
}
|
|
}()
|
|
}
|