sessionname

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 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 sessionname gives every session abcd's hooks run in a persona name, unique across the machine (itd-2610111707085098, spc-2610152057143798).

A session that starts unnamed takes the next name of its repository's persona sequence that no running named session holds: Alice, Bob, Carol and on through the list, then Alice Two, Bob Two and so on. The names handed out are kept in one machine-scoped register, the sessions folder of abcd's home, beside an entry per running session naming the host process that ran its session-start hook. An entry whose process is gone, or whose process id now belongs to a process started at another time, has ended; when every entry has ended the handed-out set is emptied and naming starts again at Alice.

The package decides and records; it never prints. Every outcome carries its diagnostics as notes for the front door to put on stderr, and naming never fails a hook: anything that goes wrong leaves the session unnamed with one note saying why (C11). The person's own name always wins: a session that arrives with a title is never given one (C4).

Everything the register reads beyond its arguments, the home folder, the process table, the process the host walk starts from and the lock's wait, is a field of Machine, so a test drives a whole machine of sessions from a fixture table and a temporary home.

Index

Constants

View Source
const PersonasRel = ".abcd/development/personas.json"

PersonasRel is the repository's persona list, repo-relative: the registry press-release composers attribute quotes from, and the source of the names sessions take.

Variables

This section is empty.

Functions

func Acts

func Acts(req Request) bool

Acts reports whether Start reads the repository's persona list for req, which is the one thing it needs req.Root for, so a front door resolves the root (a git call) only then. It answers no for every payload naming never acts on (acts), and for a startup with a title, which only records that the title is the person's (keep) and needs no repository (iss-2610152324354563).

Types

type Host

type Host struct {
	// PID is the host process's id.
	PID int
	// StartUnix is when it started, in Unix seconds: the table's read time
	// minus the process's age. With the pid it tells the process apart from a
	// later one the kernel gave the same id.
	StartUnix int64
	// Slack is how far StartUnix may be early: the length of the table read
	// it came from, capped at maxReadSlack. The read's moment is taken before
	// the read and each age somewhere inside it, so a start time is early by
	// up to the read's length and never late. Zero is a fast read, and an
	// entry written before the length was recorded.
	Slack time.Duration
}

Host is the process a session's hooks run under: the host program itself, not the shell a hook command starts in. A register entry is keyed on it, so its liveness is the session's (decision 4).

func FindHost added in v0.16.0

func FindHost(t Table, from int) (Host, error)

FindHost walks up from the process from (the hook process's parent) to the first process that is not a shell and not abcd, and returns it with its start time. A walk that leaves the table, loops, or reaches the machine's first process (pid 1, launchd or init) names no host: keyed on pid 1, an entry would never end.

type Machine

type Machine struct {
	// Home is the person's home directory, absolute; abcd's home is under it.
	// Empty names no home, and nothing is named.
	Home string
	// From is the process the host walk starts from: the hook process's
	// parent.
	From int
	// ReadTable reads the process table once.
	ReadTable func() (Table, error)
	// LockTimeout bounds the wait for the register's lock.
	LockTimeout time.Duration
}

Machine is everything the register reads beyond its arguments.

func Live

func Live() Machine

Live is this machine as the hooks see it: the account's home, the hook's parent, the process table machineload reads (one ps run on macOS, /proc on Linux, ErrUnsupported elsewhere) and the two-second lock wait.

type Outcome

type Outcome struct {
	Name  string
	Notes []string
}

Outcome is what a hook does with naming: the name (from Start, the name reserved; from Resend, the title to set on this prompt; "" for none) and the notes for stderr, raw (the front door masks them as it prints).

func Resend

func Resend(m Machine, sessionID, title string) Outcome

Resend is the prompt hook's naming: the title to set on this prompt, or "". title is the session's current title from the prompt's payload.

The name session start reserved is owed once, at the first prompt (C1, C3, decision 9), and only to a session that has no title yet: a title equal to the name is already set, and any other title is the person's own, which always wins (C4). Either way the entry is marked sent, and no later prompt sets anything. The one title replaced is a name abcd gave that a running session now holds, carried by a resumed session abcd named or by a fork (decision 10). A name set is recorded in Given, so a later resume or clear knows the title is abcd's; the person's own name is recorded as "", so a later resume never reads it as inherited.

A machine with no register touches nothing, nor does one whose sessions folder is a symlink: session start refuses that with its note, and the prompt hook does not repeat it on every prompt. The register is first read without the lock, which is enough to learn that nothing is owed, the answer on every prompt but one: the file is only ever replaced by a rename, so an unlocked read sees one whole version of it. The lock is taken only to mark the title sent.

func Start

func Start(m Machine, req Request) Outcome

Start is the session-start hook's naming.

Start reserves; it never sets a title. The host ignores a prompt-hook title equal to the one a session already has, so a title set here would never reach the session list (decision 9). The returned Name is the name reserved, which the prompt hook sets at the session's first prompt (Resend).

A sub-agent is never named, nor a payload with no session id. A new session (startup, or a fork) with no title reserves the next free name. A startup with a title is the person's own name: it is not named, and the register records that abcd gave it nothing (keep). A resumed or cleared session whose title is the name abcd gave it (Given) keeps it, and the register holds the name for the process now running it, so no other session is given it (C5). A fork, which the host starts as a new session id carrying its parent's title with source fork (seen live), inherits the name abcd gave the parent, and is held the same way. Either way, when a running session on another host holds that name, the session reserves the next free name instead, which its first prompt sets in place of the title (decision 10). Any other title is the person's, persona name or not, and is neither held nor replaced (C4). A compaction of a titled session changes nothing: the host keeps the title through it.

A resume, clear or compaction with no title is a session whose first prompt has not set its name yet (rejoin): its entry is re-keyed to the process now running it, or, when it has none, it reserves the next free name as a new session does.

type Request

type Request struct {
	// Root is the repository root the session works in, whose persona list
	// names it; empty takes the bundled list.
	Root string
	// SessionID is the host's id for the session. A session without one is
	// never named: the prompt hook finds its entry by it.
	SessionID string
	// Source is why the session started: startup, resume, clear, compact or
	// fork.
	Source string
	// Title is the session's current custom title: a name the person gave it,
	// or one a hook set earlier. Empty when it has none.
	Title string
	// AgentID is set on a sub-agent's payload, which is never named (C12).
	AgentID string
}

Request is what a session-start hook's payload says about the session.

type Table

type Table struct {
	Procs  []machineload.Proc
	ReadAt time.Time
	// Took is how long the read took: how far, at most, a start time computed
	// from the table is early.
	Took time.Duration
}

Table is one reading of the process table and the moment the read began, which is what a process's age is measured from.

func (Table) Alive

func (t Table) Alive(h Host) bool

Alive reports whether h is running: its process id is in the table, and the process holding it started when h says, within startTolerance widened by each reading's slack (C9).

Jump to

Keyboard shortcuts

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