accounts

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 16 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

func ParseColor added in v0.12.0

func ParseColor(s string) (string, error)

ParseColor is the one place a colour is accepted: exactly "#" and six hex digits (either case), returned in lower case. Nothing else is a colour -- no name, no short form, no rgb() or url() -- so a stored value can never carry markup or CSS.

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 Colors added in v0.12.0

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

Colors are the colours the owner gave accounts, by account hash, kept in dir/account-colors.toml next to the aliases:

"7567" = "#e69f00"

An account without an entry keeps its automatic colour. A missing or corrupt file means no colour at all; one entry that is not a colour is dropped, the others are kept. The file is read through a size bound and written atomically, mode 0600, only by the serve process.

func NewColors added in v0.12.0

func NewColors(dir string) *Colors

NewColors keeps colours in dir/account-colors.toml and loads them. A key is the first 4 hex digits of an account hash or the whole hash, as for Aliases.

func (*Colors) Color added in v0.12.0

func (c *Colors) Color(key string) string

Color is the colour of the account with the hash key, "" when it has none (its automatic colour applies).

func (*Colors) Reload added in v0.12.0

func (c *Colors) Reload()

Reload reads the file again (the owner may have edited it by hand).

func (*Colors) Set added in v0.12.0

func (c *Colors) Set(key, color string) error

Set gives the account a colour, or restores its automatic one when color is empty, and writes the file. A colour that is not #rrggbb is refused and nothing is written.

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 Prefs added in v0.13.0

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

Prefs are the viewer's theme and language, kept in dir/settings.toml next to account-colors.toml:

theme = "dark"
lang = "fr"

A missing or corrupt file means nothing chosen; a value that is not a theme or a language is dropped, the other is kept. The file is read through a size bound and written atomically, mode 0600, only by the serve process.

func NewPrefs added in v0.13.0

func NewPrefs(dir string) *Prefs

NewPrefs keeps the preferences in dir/settings.toml and loads them.

func (*Prefs) Get added in v0.13.0

func (p *Prefs) Get() model.Prefs

Get is what is chosen now.

func (*Prefs) Reload added in v0.13.0

func (p *Prefs) Reload()

Reload reads the file again (the owner may have edited it by hand).

func (*Prefs) Set added in v0.13.0

func (p *Prefs) Set(theme, lang string) error

Set stores a choice and writes the file. An empty theme or language means "not chosen" (system, automatic); anything else must pass ParseTheme or ParseLang, or the whole call is refused and nothing is written.

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