sessiontags

package
v0.292.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 9 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 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

View Source
const MaxPerTarget = notes.MaxTags

MaxPerTarget bounds one subject's tags (a task's own cap, notes.MaxTags).

View Source
const MaxTagRunes = notes.MaxTagRunes

MaxTagRunes bounds one tag (notes.MaxTagRunes).

Variables

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

View Source
var ErrInvalid = errors.New("sessiontags: invalid tag")

ErrInvalid wraps a tag the grammar refuses (its message names the tag).

Functions

func Normalize

func Normalize(raw string) (string, error)

Normalize is raw as it is stored, or an error: ErrEmpty for nothing, ErrInvalid (naming the tag) for what the grammar refuses.

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 NewPG

func NewPG(pool *pgxpool.Pool) *PGStore

NewPG returns a Store on pool.

func (*PGStore) Add

func (s *PGStore) Add(ctx context.Context, t Target, raw string) ([]string, error)

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.

func (*PGStore) For

func (s *PGStore) For(ctx context.Context, t Target) ([]string, error)

For is t's tags, sorted; none is an empty (non-nil) slice.

func (*PGStore) List

func (s *PGStore) List(ctx context.Context) (Set, error)

List is the caller's tags, by subject.

func (*PGStore) Remove

func (s *PGStore) Remove(ctx context.Context, t Target, raw string) ([]string, error)

Remove takes raw (normalized) off t for the caller. Idempotent. A tag that does not normalize is not on any subject, so removing it changes nothing.

type Set

type Set struct {
	Agents  map[int64][]string
	Mirrors map[MirrorKey][]string
}

Set is one user's tags, by subject, each sorted.

func (Set) Agent

func (s Set) Agent(id int64) []string

Agent is agent id's tags (nil for none).

func (Set) Mirror

func (s Set) Mirror(host, session string) []string

Mirror is the mirrored session's tags (nil for none).

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.

type Target

type Target struct {
	AgentID int64
	Host    string
	Session string
}

Target is one subject: an agent (AgentID > 0) or a mirrored tmux session (Host, Session). Exactly one of the two.

func (Target) Mirror

func (t Target) Mirror() bool

Mirror reports whether t names a mirrored session.

func (Target) Valid

func (t Target) Valid() error

Valid reports whether t names exactly one subject the store can key.

Jump to

Keyboard shortcuts

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