Documentation
¶
Overview ¶
Package live decides what is running: Claude Code's live-session registry, the state word a hook left, and how long a session's transcript has been quiet. The rules are the bash ones (live_ids, deadp, tquiet and stext in bin/sitrep).
Index ¶
- Constants
- func Age(secs int64) string
- func AttachClients(procs []Proc, sessionID string) []int
- func Blocked(s state.Store, configDir, id, word string, now int64) (kind string, at int64, ok bool)
- func Changed(s state.Store, id string) (int64, bool)
- func Clients(procs []Proc, set Set, next func(id string) (string, bool)) map[string][]int
- func ContinuedIn(configDir, id string) (string, bool)
- func Continues(next func(id string) (string, bool), from, to string) bool
- func Dead(set Set, id, word string, changed, now int64) bool
- func IsIdle(word string, quiet int64, hasQuiet bool) bool
- func Label(word string, changed, now int64, quiet int64, hasQuiet bool) string
- func LocalDomain() string
- func Next(configDir string, st state.Store, isLive func(id string) bool, id string) (string, bool)
- func Quiet(configDir, id string, now int64) (int64, bool)
- func Word(s state.Store, id string) string
- type Entry
- type Proc
- type Registry
- type Set
Constants ¶
const (
BlockPermission = "permission"
)
Block kinds a hook records.
const BlockedSlack = 3
BlockedSlack is how long after a block the transcript may still be written, in seconds: Claude Code writes it once, 0.3 s after a dialog opens.
const Grace = 120
Grace is how long a session that is not in the registry may stay quiet before it counts as over: the registry lags a start and a /clear.
const IdleAfter = 600
IdleAfter is how long a working session's transcript may stay quiet before the session is shown as idle?.
const MaxName = 64
PID is the first live process of a session, when it runs on this machine. MaxName is the longest name of a session that is kept.
Variables ¶
This section is empty.
Functions ¶
func AttachClients ¶ added in v1.3.3
AttachClients finds the `claude attach <prefix>` processes that show the session. The argument is a prefix of the session id; a client counts only if it names this session.
func Blocked ¶ added in v1.0.0
Blocked says whether a session is stopped at a dialog, and since when (seconds since the epoch). The permission hook wrote the file `blocked`; the block counts only while the session is working and its transcript has not been written since, so that an answered dialog and a crash leave nothing behind once the next transcript line is written, which for a long tool is when it finishes. A session without a readable transcript keeps the block until the file is removed.
func Changed ¶
Changed is when a session's state last changed, in seconds since the epoch: the state file's time, else the notes file's.
func Clients ¶ added in v1.3.3
Clients maps each live background session to the pids of the terminal clients that show it. next gives the session that a resume moved a conversation into.
func ContinuedIn ¶ added in v1.3.3
ContinuedIn is the session that a resume moved a conversation into, from the end of the old transcript.
func Continues ¶ added in v1.3.3
Continues says whether the conversation of from went on, through one or more links that next follows, as to.
func Dead ¶
Dead says whether a session is over. With a readable registry a live process settles it; otherwise the session is over once it said so, or after two quiet minutes. Without a registry only its own word counts.
func IsIdle ¶ added in v1.1.0
IsIdle says whether a working session's transcript has been quiet long enough for it to be shown as idle?.
func Label ¶
Label is the state column: "waiting 3m". A working session whose transcript has been quiet for ten minutes is "idle? 12m".
func LocalDomain ¶
func LocalDomain() string
LocalDomain is how Claude Code names this machine's pid space.
func Next ¶ added in v1.6.2
Next is the session that a conversation went on as: the one a resume moved it into, from the end of the old transcript, and else the one that `sitrep adopt` recorded after a /clear (docs/ADOPT-LINK.md), while that record holds. It holds while the old session is not live again and its transcript has not been written since the record was, as both happen when the user goes back to the old conversation.
Types ¶
type Entry ¶
type Entry struct {
ID state.ID
PID int
// Bg is true for a background session (kind "bg"), which has no terminal of its own. BgIdle is true when the registry also calls it
// idle.
Bg, BgIdle bool
// Name is what Claude Code calls the session among its peers, the name that SendMessage takes: made up by Claude Code, from the folder or
// from a title a model wrote, so it is cleaned and short, and it can change.
Name textsafe.Text
}
Entry is one live session. PID is 0 when the process is in another pid space and cannot be judged here.
type Proc ¶ added in v1.3.3
Proc is one line of `ps -A -o pid=,ppid=,command=`.
func ParseProcs ¶ added in v1.3.3
ParseProcs reads the output of `ps -A -o pid=,ppid=,command=`.
type Registry ¶
type Registry struct {
Dir string // the sessions folder
Run runner.Runner // for ps
Alive func(pid int) bool
Domain string // how Claude Code names this machine's pid space; empty when it cannot be worked out
}
Registry reads ~/.claude/sessions/<pid>.json. Its files are untrusted input, so everything used is checked.
func NewRegistry ¶
NewRegistry is the registry of a Claude config folder, with the real process checks.
type Set ¶
Set is what the registry says is live. OK is false when nothing live could be read, which means the registry cannot be trusted either way.
func (Set) Bg ¶ added in v1.3.3
Bg says whether the registry shows this session as a background session.
func (Set) BgIdle ¶ added in v1.3.3
BgIdle says whether the registry shows this session as an idle background session.