chiefpref

package
v0.327.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxRefusal = 500

MaxRefusal bounds a stored refusal, in runes (the column's CHECK).

Variables

View Source
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.

View Source
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)
}

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 NewMemHost added in v0.327.0

func NewMemHost() *MemHost

NewMemHost is an empty MemHost.

func (*MemHost) BeginChiefSpawn added in v0.327.0

func (m *MemHost) BeginChiefSpawn(_ context.Context, owner int64, host string) (HostChief, error)

BeginChiefSpawn implements HostStore.

func (*MemHost) HostChief added in v0.327.0

func (m *MemHost) HostChief(ctx context.Context, owner int64) (HostChief, error)

HostChief 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.

func (*MemHost) RecordChiefSpawnWindow added in v0.327.0

func (m *MemHost) RecordChiefSpawnWindow(_ context.Context, owner, id int64, host, window, session string) (bool, error)

RecordChiefSpawnWindow implements HostStore.

type PG

type PG struct {
	// contains filtered or unexported fields
}

PG is Store on chief_preferences, under row-level security.

func NewPG

func NewPG(pool *pgxpool.Pool) *PG

NewPG is Store over pool.

func (*PG) BeginChiefSpawn added in v0.327.0

func (p *PG) BeginChiefSpawn(ctx context.Context, owner int64, host string) (HostChief, error)

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

func (p *PG) Choice(ctx context.Context, owner int64) (bool, bool, error)

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) HostChief added in v0.327.0

func (p *PG) HostChief(ctx context.Context, owner int64) (HostChief, error)

HostChief 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) RecordChiefSpawnWindow added in v0.327.0

func (p *PG) RecordChiefSpawnWindow(ctx context.Context, owner, id int64, host, window, session string) (bool, error)

RecordChiefSpawnWindow implements HostStore.

func (*PG) SetEnabled

func (p *PG) SetEnabled(ctx context.Context, owner int64, on bool) error

SetEnabled implements Store: the CALLER's row (row-level security refuses another owner's).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL