state

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 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 state is where sitrep keeps its files: the folder, the session ids that name them, and the way they are written.

Index

Constants

View Source
const (
	FileMode os.FileMode = 0o600
	DirMode  os.FileMode = 0o700
)

Modes for everything sitrep writes (invariant 2): state holds prompt text, so it is owner-only. A Umask call does not reach in-process tests, so the modes are always explicit.

Variables

View Source
var ErrBusy = errors.New("busy: another sitrep is changing the same files")

ErrBusy says a lock could not be taken in time.

Functions

func ConfigDir

func ConfigDir(getenv func(string) string, home string) string

ConfigDir is Claude Code's own folder. Only the transcripts and the live-session registry honor CLAUDE_CONFIG_DIR; sitrep's own state never moves (see Open), and unifying the two would orphan existing state.

func FirstLine

func FirstLine(path string) string

FirstLine is the first line of a small regular file, without leading or trailing spaces and tabs, as the shell's read -r gives it. It is empty when the file cannot be read.

func IsRegular

func IsRegular(path string) bool

IsRegular says whether path is a regular file (a link to one counts).

func Lock

func Lock(path string) (unlock func(), err error)

Lock takes an exclusive lock on a file (made if needed), waiting a moment for another holder, and gives up rather than hang a prompt. The returned function releases it. Locks are advisory: every writer of what the lock guards takes it.

func ReadFile

func ReadFile(path string, max int64) ([]byte, error)

ReadFile reads at most max bytes of a regular file, and nothing else: a pipe, a device or a directory is an error, and opening one never blocks (invariant 4: a hook must not hang on a hostile file). A link to a regular file is followed, as the bash tests did.

func SessionID

func SessionID(s string) bool

SessionID is ValidID for a real session: the inbox is not one.

func ValidID

func ValidID(s string) bool

ValidID reports whether s can be part of a file name: letters, digits, underscore and hyphen, and nothing else (invariant 3).

Types

type ID

type ID string

ID names a queue: a session id, or the inbox. It can only be made by ParseID or Resolve, so a path built from an ID cannot leave the state folder (invariant 3).

const Inbox ID = "inbox"

Inbox is the queue of no session. It is reserved: no session id may be this.

func ParseID

func ParseID(s string) (ID, error)

ParseID checks that s is a valid id (the inbox included).

type Store

type Store struct{ Dir string }

Store is the state folder.

func Open

func Open(home string) Store

Open names the state folder, always ~/.claude/sitrep, whatever CLAUDE_CONFIG_DIR says. It creates nothing.

func (Store) Ensure

func (s Store) Ensure() error

Ensure creates the folder if needed and makes it owner-only.

func (Store) Hidden

func (s Store) Hidden(id ID, ext string) string

Hidden is the dot file kept beside them: .<id>.state, .<id>.count, and so on.

func (Store) Path

func (s Store) Path(id ID, ext string) string

Path is the file for a session id and an extension without the dot: <id>.txt, <id>.queue, <id>.cwd.

func (Store) Resolve

func (s Store) Resolve(prefix string) (ID, error)

Resolve turns a unique prefix of a session id into the full id. "inbox" matches exactly. The error text is safe to print.

It is stricter than the bash it replaces: only files named <valid id>.txt count, so inbox.txt and a.b.txt never match by prefix.

func (Store) WriteFile

func (s Store) WriteFile(path string, data []byte) error

WriteFile replaces path with data in one step: a reader sees the old file or the new one, never a half. The temporary file has a unique name in the same folder and is removed if anything fails.

Jump to

Keyboard shortcuts

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