contextsize

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package contextsize measures how large an agent's conversation context is from the usage numbers its launcher writes locally (hadron-cli#2063, the client half of hadron-server#4238 S4a).

It is deliberately narrow, like internal/modelreport:

  • Only numbers and a timestamp are decoded. Every record is unmarshalled into a struct that has no field for message content, so transcript text is never held, returned, logged or sent.
  • Any doubt returns nil: a missing, unreadable, oversized, unattributable or implausible record yields NO measurement, never a zero.
  • A file is attributed to a worker only when the file itself records the worker's worktree as its cwd; a directory-name match alone is not proof.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Measurement

type Measurement struct {
	Tokens     int
	MeasuredAt time.Time
}

Measurement is one context-size reading: both fields are always set together.

func ClaudeFromFile

func ClaudeFromFile(path, worktree string, now time.Time) (*Measurement, bool)

ClaudeFromFile reads the latest main-thread assistant usage record of a Claude Code transcript whose own cwd is worktree. Context is input + cache-read + cache-creation input tokens of that turn.

func CodexFromFile

func CodexFromFile(path string, now time.Time) (*Measurement, bool)

CodexFromFile reads the latest token_count event of a Codex rollout. The context is the last turn's input tokens (Codex counts cached input inside input_tokens), not the running total, which only grows.

func Measure

func Measure(family string, worktrees []string, roots Roots, now time.Time) *Measurement

Measure returns the newest context-size reading for a worker running the given model family in any of the worktrees, or nil. Only the families "claude" and "codex" have a measurer; every other family returns nil. `now` bounds a reading that claims to be from the future.

type Roots

type Roots struct {
	ClaudeProjects string // e.g. ~/.claude/projects
	CodexSessions  string // e.g. ~/.codex/sessions
}

Roots are the directories the supported launchers write sessions under.

func DefaultRoots

func DefaultRoots() Roots

DefaultRoots honours CLAUDE_CONFIG_DIR and CODEX_HOME like the tools do.

Jump to

Keyboard shortcuts

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