accounts

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 15 Imported by: 1 module, 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 accounts is what agentscope knows about WHO a call was made as: the signed-in account (read from ~/.claude.json), the stamps the `stamp` hook appends when it changes, and the display names the owner gives accounts.

An account is known by a short hash of its id and a label; its e-mail and its id are never kept. The organisation's name is read only when the owner asks for it (--show-org), and only to suggest a display name.

Index

Constants

View Source
const (

	// MaxName is the longest display name, in bytes.
	MaxName = 64
)

Bounds on the alias file: it is a hand-edited list of a few accounts.

View Source
const (
	// RotateBytes is the size past which accounts.jsonl is renamed to
	// accounts.jsonl.1 (the previous one is dropped): a stamp is written once per
	// CHANGE of account, so a file this large is years of switching.
	RotateBytes = 256 << 10
)

Bounds on the stamp file.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aliases

type Aliases struct {
	// contains filtered or unexported fields
}

Aliases are the display names the owner gave accounts, by account hash, kept in dir/accounts.toml:

"7567" = "Labo (team)"

A missing or corrupt file means no alias at all, never an error on screen: the account is then shown as "label #hash". The file is written atomically, mode 0600, only by the serve process.

func NewAliases

func NewAliases(dir string) *Aliases

NewAliases keeps aliases in dir/accounts.toml and loads them. A key is the first 4 hex digits of an account hash (what the screen shows after "#") or the whole hash.

func (*Aliases) Name

func (a *Aliases) Name(key string) string

Name is the display name of the account with the hash key, "" when it has none.

func (*Aliases) Reload

func (a *Aliases) Reload()

Reload reads the file again (the owner may have edited it by hand). A file that cannot be read or parsed leaves no aliases.

func (*Aliases) Set

func (a *Aliases) Set(key, name string) error

Set gives the account a display name, or removes its alias when name is empty (after trimming), and writes the file. The name is bounded and must not carry control characters.

type Identity

type Identity struct {
	// Key is the 8 hex digit hash of the account id (see quota.AccountKey).
	Key string
	// Label is "Claude Code", and its plan in brackets when one is known.
	Label string
	// Plan is the subscription ("team", "max", ...), "" when unknown.
	Plan string
	// Org is the organisation's name: set only when the caller asked for it.
	Org string
}

Identity is the signed-in account as agentscope names it.

func ReadIdentity

func ReadIdentity(path string, withOrg bool) (id Identity, ok bool)

ReadIdentity reads the signed-in account from the .claude.json at path. ok is false when the file cannot be read, is no JSON object, or names no account: nothing is guessed. withOrg says whether the organisation's name is read.

type Stamp

type Stamp struct {
	At          time.Time `json:"at"`
	SessionID   string    `json:"session_id,omitempty"`
	AccountHash string    `json:"account_hash"`
	Label       string    `json:"label,omitempty"`
	Plan        string    `json:"plan,omitempty"`
}

Stamp says that from At on, calls were made as an account: what the `stamp` hook appends, once per change of account, to accounts.jsonl.

type Stamps

type Stamps struct {
	// contains filtered or unexported fields
}

Stamps is the stamp file in a directory.

func NewStamps

func NewStamps(dir string) *Stamps

NewStamps keeps stamps in dir/accounts.jsonl; dir is created when first written.

func (*Stamps) Append

func (s *Stamps) Append(st Stamp) (wrote bool, err error)

Append adds st, unless the last stamp already names the same account, which reports false. It is safe against any number of concurrent writers (sessions share the file): the check and the append happen under one lock.

func (*Stamps) Load

func (s *Stamps) Load() Timeline

Load reads every stamp kept, oldest first. A line that does not parse is skipped: a torn write or a hand edit must not hide the rest.

type Timeline

type Timeline struct {
	// contains filtered or unexported fields
}

Timeline is the stamps, oldest first.

func (Timeline) At

func (tl Timeline) At(t time.Time) (Stamp, bool)

At is the account a call at t was made as: the latest stamp at or before t. ok is false when no stamp is that old.

func (Timeline) Latest

func (tl Timeline) Latest(hash string) (Stamp, bool)

Latest is the newest stamp of the account with the hash, the one that carries its label and plan as the hook last saw them.

func (Timeline) Len

func (tl Timeline) Len() int

Len is the number of stamps.

Jump to

Keyboard shortcuts

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