Documentation
¶
Overview ¶
Package sessiontags is the labels a user puts on a session (migration session_tags): per user, server-stored, and private — like pins and recents. A tag names either a dispatched agent (by id) or a mirrored tmux SESSION (host + session name; every window of the session shares them).
🔴 EVERY METHOD RUNS UNDER THE CALLER'S PRINCIPAL. session_tags is under FORCE row-level security, so a request sees, adds and removes only its own user's rows; there is no system method. The owner of a new row is the principal's user (owner_id's default), never a parameter.
🔴 ONE TAG RULE: the task tags' (internal/notes). A tag is normalized by notes.NormalizeTag (lower case, white space to '-'; the browser runs the same rule, internal/ui/js/tag-normalize.js) and must pass notes.ValidateTags' per-tag checks (charset, MaxTagRunes, one ':'). Because the stored tag is the normalized one, two spellings that differ only in case are one tag.
🔴 RESERVED NAMESPACES CARRY NO BEHAVIOUR HERE. A task's `gate:`, `initiative:`, `auto:` and `project:` tags route; a session's do not — nothing reads a session tag but its owner's own header, editor and search. So a session tag is never refused for its namespace (a session may carry two `project:` tags, which a task may not) and is drawn as a plain label. The grammar is otherwise the task tags', so one tag means one spelling everywhere.
Index ¶
Constants ¶
const MaxPerTarget = notes.MaxTags
MaxPerTarget bounds one subject's tags (a task's own cap, notes.MaxTags).
const MaxTagRunes = notes.MaxTagRunes
MaxTagRunes bounds one tag (notes.MaxTagRunes).
Variables ¶
var ( // ErrBadTarget refuses a target that names no subject, or two. ErrBadTarget = errors.New("sessiontags: name an agent or a mirrored session") // ErrNoSuchAgent refuses a tag on an agent the caller cannot see (absent, // or another user's — the two answer identically). ErrNoSuchAgent = errors.New("sessiontags: no such agent") // ErrTooMany refuses a tag past MaxPerTarget. ErrTooMany = fmt.Errorf("sessiontags: a session may carry at most %d tags; remove one first", MaxPerTarget) // ErrEmpty refuses a tag that normalizes to nothing. ErrEmpty = errors.New("sessiontags: the tag is empty") )
Errors the store answers with; the API maps each to a status.
var ErrInvalid = errors.New("sessiontags: invalid tag")
ErrInvalid wraps a tag the grammar refuses (its message names the tag).
Functions ¶
Types ¶
type MirrorKey ¶
type MirrorKey struct{ Host, Session string }
MirrorKey is a mirrored session's key in a Set.
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
PGStore is Store on Postgres.
func (*PGStore) Add ¶
Add adds raw (normalized) to t for the caller. Idempotent: a tag t already carries, in any case, is no new row and is not refused at the cap.
The cap is checked AFTER the insert, in the same transaction, serialised per owner by an advisory lock (pins.insert's shape): two concurrent adds cannot both pass it.
type Store ¶
type Store interface {
// List is every tag of the caller's, by subject.
List(ctx context.Context) (Set, error)
// For is one subject's tags, sorted.
For(ctx context.Context, t Target) ([]string, error)
// Add normalizes raw and adds it to t; idempotent. It answers the
// subject's tags after the add.
Add(ctx context.Context, t Target, raw string) ([]string, error)
// Remove takes raw (normalized) off t; idempotent. It answers the
// subject's tags after the removal.
Remove(ctx context.Context, t Target, raw string) ([]string, error)
}
Store is the session tags' persistence.