Documentation
¶
Overview ¶
Package chiefpref stores each user's choice to turn their chief on or off (migration 0060, chief_preferences). It stores only the CHOICE: whether the chief is on for a user who never chose is internal/api's rule (chiefOn), so the default lives in one place.
Index ¶
- Constants
- Variables
- type HostChief
- type HostStore
- type MemHost
- func (m *MemHost) BeginChiefSpawn(_ context.Context, owner int64, host string) (HostChief, error)
- func (m *MemHost) HostChief(ctx context.Context, owner int64) (HostChief, error)
- func (m *MemHost) HostChiefs(ctx context.Context) (map[int64]string, error)
- func (m *MemHost) RecordChiefSpawnRefusal(_ context.Context, owner, id int64, host, refusal string) (bool, error)
- func (m *MemHost) RecordChiefSpawnSession(_ context.Context, owner, id int64, host, window, session string) (bool, error)
- func (m *MemHost) RecordChiefSpawnWindow(_ context.Context, owner, id int64, host, window, session string) (bool, error)
- type PG
- func (p *PG) BeginChiefSpawn(ctx context.Context, owner int64, host string) (HostChief, error)
- func (p *PG) Choice(ctx context.Context, owner int64) (bool, bool, error)
- func (p *PG) HostChief(ctx context.Context, owner int64) (HostChief, error)
- func (p *PG) HostChiefs(ctx context.Context) (map[int64]string, error)
- func (p *PG) RecordChiefSpawnRefusal(ctx context.Context, owner, id int64, host, refusal string) (bool, error)
- func (p *PG) RecordChiefSpawnSession(ctx context.Context, owner, id int64, host, window, session string) (bool, error)
- func (p *PG) RecordChiefSpawnWindow(ctx context.Context, owner, id int64, host, window, session string) (bool, error)
- func (p *PG) SetEnabled(ctx context.Context, owner int64, on bool) error
- type Store
Constants ¶
const MaxRefusal = 500
MaxRefusal bounds a stored refusal, in runes (the column's CHECK).
Variables ¶
var ErrNotOwner = errors.New("chiefpref: the toggle is read only as its owner or as the system")
ErrNotOwner refuses a read whose ctx can see neither owner's row nor every row.
var ErrNotOwnerHost = errors.New("chiefpref: the host chief is read only as its owner or as the system")
ErrNotOwnerHost refuses a read whose ctx can see neither owner's row nor every row (Choice's rule: an invisible row would read as "no machine").
Functions ¶
This section is empty.
Types ¶
type HostChief ¶ added in v0.327.0
type HostChief struct {
// Host is the mirror host chosen, "" for none.
Host string
// SpawnID is the latest spawn's id (its `dispatch` on the wire), 0 for
// none.
SpawnID int64
// Window and Session are what the host's reply named: the tmux window id
// and the Claude session id. "" until the reply.
Window, Session string
// Refusal is the host's refusal ("code: detail"), "" for none.
Refusal string
// SpawnedAt is when the spawn was recorded (zero for none).
SpawnedAt time.Time
}
HostChief is an owner's host chief: the machine chosen and the spawn record. The zero value is "no machine chosen".
type HostStore ¶ added in v0.327.0
type HostStore interface {
// HostChief is owner's host chief (the zero value: none chosen).
HostChief(ctx context.Context, owner int64) (HostChief, error)
// BeginChiefSpawn chooses host for owner's chief and records a new spawn
// about to be sent there, with a fresh id from the host-dispatch
// sequence and no outcome yet. It replaces any earlier record.
BeginChiefSpawn(ctx context.Context, owner int64, host string) (HostChief, error)
// RecordChiefSpawnWindow records the host's reply on owner's spawn id,
// ONLY when that spawn is still the record, was sent to host, and has no
// outcome yet: reporting whether it wrote.
RecordChiefSpawnWindow(ctx context.Context, owner, id int64, host, window, session string) (bool, error)
// RecordChiefSpawnRefusal records the host's refusal under the same rule.
RecordChiefSpawnRefusal(ctx context.Context, owner, id int64, host, refusal string) (bool, error)
// RecordChiefSpawnSession moves owner's recorded Claude session to session
// (PR 5b: a /clear in the chief's window, or Claude Code restarted there),
// ONLY when spawn id is still the record, on host, its reply named window
// (not ""), it was not refused, and the session differs: reporting whether
// it wrote. The window never moves: it is muster's record.
RecordChiefSpawnSession(ctx context.Context, owner, id int64, host, window, session string) (bool, error)
// HostChiefs is every owner's chosen host ("" never listed), for the host
// chief's sweep (PR 5b). ctx must see every row (authz.System).
HostChiefs(ctx context.Context) (map[int64]string, error)
}
HostStore keeps each owner's host chief. Every call acts as the principal on ctx; row-level security confines it to that principal's own row.
type MemHost ¶ added in v0.327.0
type MemHost struct {
NextID int64
// Now is the clock (time.Now when nil).
Now func() time.Time
// contains filtered or unexported fields
}
MemHost is HostStore in memory, for tests: the same write rules, ids from its own counter (NextID, starting at 9000 so they are distinct from any fixture's dispatch ids).
func (*MemHost) BeginChiefSpawn ¶ added in v0.327.0
BeginChiefSpawn implements HostStore.
func (*MemHost) HostChiefs ¶ added in v0.330.0
HostChiefs implements HostStore.
func (*MemHost) RecordChiefSpawnRefusal ¶ added in v0.327.0
func (m *MemHost) RecordChiefSpawnRefusal(_ context.Context, owner, id int64, host, refusal string) (bool, error)
RecordChiefSpawnRefusal implements HostStore.
type PG ¶
type PG struct {
// contains filtered or unexported fields
}
PG is Store on chief_preferences, under row-level security.
func (*PG) BeginChiefSpawn ¶ added in v0.327.0
BeginChiefSpawn implements HostStore. A user with no row yet gets one that is on: choosing a machine is turning the chief on.
func (*PG) Choice ¶
Choice implements Store.
🔴 IT REFUSES A ctx THAT ROW-LEVEL SECURITY WOULD BLIND. A row of owner's is invisible to any other user's principal and to a principal-less ctx, and an invisible row reads as "never chose", which falls back to "on if a chief agent exists": a user who turned their chief OFF would get it back on any path that read the toggle with the wrong principal. So only owner's own principal or the system scope may read, and anything else is an error the caller reads as off.
func (*PG) HostChiefs ¶ added in v0.330.0
HostChiefs implements HostStore.
func (*PG) RecordChiefSpawnRefusal ¶ added in v0.327.0
func (p *PG) RecordChiefSpawnRefusal(ctx context.Context, owner, id int64, host, refusal string) (bool, error)
RecordChiefSpawnRefusal implements HostStore.
func (*PG) RecordChiefSpawnSession ¶ added in v0.330.0
func (p *PG) RecordChiefSpawnSession(ctx context.Context, owner, id int64, host, window, session string) (bool, error)
RecordChiefSpawnSession implements HostStore.
type Store ¶
type Store interface {
// Choice is owner's stored choice: chose is false when owner never
// turned the chief on or off (no row), and on is then meaningless.
Choice(ctx context.Context, owner int64) (chose, on bool, err error)
// SetEnabled records owner's choice.
SetEnabled(ctx context.Context, owner int64, on bool) error
}
Store is the per-user chief toggle.