model

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 1 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 model holds the shared, frozen types of MyToken!!!!!. Changing any exported signature here requires lead approval (docs/ARCHITECTURE.md#data-model).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttribSource

type AttribSource string

AttribSource records how a provider was determined.

const (
	AttribLog      AttribSource = "log"
	AttribCCSwitch AttribSource = "cc-switch"
	AttribConfig   AttribSource = "config-timeline"
	AttribInferred AttribSource = "inferred"
	AttribUserRule AttribSource = "user-rule"
)

type Bill

type Bill struct {
	Amount float64 `json:"amount"`
	Unit   string  `json:"unit"`
}

Bill preserves a tool's explicitly reported charge in its native unit. It is independent of CostUSD: credits are never converted to or added to USD.

type Boundary

type Boundary string

Boundary is an explicitly observed context lifecycle change before a request. Empty means unknown; missing records and model changes are not boundaries.

const (
	BoundaryCompact Boundary = "compact"
	BoundaryClear   Boundary = "clear"
	BoundaryResume  Boundary = "resume"
)

type Harness

type Harness string

Harness identifies the AI coding tool that produced a log.

const (
	ClaudeCode    Harness = "claude-code"
	Codex         Harness = "codex"
	Gemini        Harness = "gemini"
	DSH           Harness = "dsh"
	OpenCode      Harness = "opencode"
	Crush         Harness = "crush"
	Cline         Harness = "cline"
	Roo           Harness = "roo"
	Kilo          Harness = "kilo"
	Pi            Harness = "pi"
	Grok          Harness = "grok"
	OpenClaw      Harness = "openclaw"
	Droid         Harness = "droid"
	Goose         Harness = "goose"
	Forge         Harness = "forge"
	ClaudeDesktop Harness = "claude-desktop"
	Qwen          Harness = "qwen"
	Kimi          Harness = "kimi"
	OpenClaude    Harness = "openclaude"
	WorkBuddy     Harness = "workbuddy"
	CodeBuddy     Harness = "codebuddy"
	CodeBuddyCN   Harness = "codebuddy-cn"
	Cindy         Harness = "cindy"
	Hermes        Harness = "hermes"
	Amp           Harness = "amp"
	Kiro          Harness = "kiro"
	Codebuff      Harness = "codebuff"
	Mux           Harness = "mux"
	Zed           Harness = "zed"
	Antigravity   Harness = "antigravity"
	ZCode         Harness = "zcode"
	MiniMaxCode   Harness = "minimax-code"
	MiMoCode      Harness = "mimo-code"
	StepCode      Harness = "step-code"
	Trae          Harness = "trae"
	Qoder         Harness = "qoder"
)

func (Harness) DisplayName

func (h Harness) DisplayName() string

DisplayName is the human label of a harness.

func (Harness) Known

func (h Harness) Known() bool

Known reports whether h is one of the harnesses MyToken reads.

type SessionMeta

type SessionMeta struct {
	Harness   Harness   `json:"harness"`
	SessionID string    `json:"sessionId"`
	ParentID  string    `json:"parentId,omitempty"`
	Title     string    `json:"title,omitempty"` // first user message, ≤60 runes, no newlines
	Project   string    `json:"project,omitempty"`
	StartedAt time.Time `json:"startedAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

SessionMeta describes a session. Title is the only conversation text stored.

type Tokens

type Tokens struct {
	Input      int64 `json:"input"`
	Output     int64 `json:"output"`
	CacheRead  int64 `json:"cacheRead"`
	CacheWrite int64 `json:"cacheWrite"`
	// CacheWrite1h is the part of CacheWrite written with the 1-hour TTL
	// (Anthropic cache_creation.ephemeral_1h_input_tokens). It is a subset,
	// never added on top: CacheWrite is always the total of both tiers, and
	// CacheWrite-CacheWrite1h is the 5-minute tier. Priced at 2x input
	// instead of 1.25x.
	CacheWrite1h int64 `json:"cacheWrite1h,omitempty"`
	Reasoning    int64 `json:"reasoning"`
}

Tokens are the five token classes. Parsers must not double count: if a log's output already includes reasoning, Output must exclude it.

func (Tokens) Add

func (t Tokens) Add(o Tokens) Tokens

Add returns t+o.

func (Tokens) HitRate

func (t Tokens) HitRate() float64

HitRate is the one cache hit-rate formula MyToken shows anywhere: cache_read / (input + cache_read + cache_write). It is 0 when there was no prompt at all.

func (Tokens) IsZero

func (t Tokens) IsZero() bool

IsZero reports whether all classes are zero.

func (Tokens) Total

func (t Tokens) Total() int64

Total sums all five classes (CacheWrite1h is inside CacheWrite).

type UsageEvent

type UsageEvent struct {
	Harness     Harness   `json:"harness"`
	DedupKey    string    `json:"dedupKey"`  // stable; harness request/message id, else sha1(file+offset)
	SessionID   string    `json:"sessionId"` // subagents use their own id
	ParentID    string    `json:"parentId,omitempty"`
	ProjectPath string    `json:"projectPath,omitempty"`
	Timestamp   time.Time `json:"timestamp"` // UTC
	Model       string    `json:"model"`
	Provider    string    `json:"provider,omitempty"` // set only when the log itself says so
	BaseURL     string    `json:"baseUrl,omitempty"`
	Tokens      Tokens    `json:"tokens"`
	CostUSD     *float64  `json:"costUsd,omitempty"`   // cost reported by the log, if any
	RequestID   string    `json:"requestId,omitempty"` // upstream request/response ID, never a local fallback
	Boundary    Boundary  `json:"boundary,omitempty"`
	Bill        *Bill     `json:"bill,omitempty"`
	// DecodeMS is the generation window of this request in milliseconds, when
	// the log itself timed it: the distance from the first streamed output
	// token to the record that closed the message. Only a tool that journals its
	// own token stream can report it. It is a measurement, never a guess; zero
	// means the log did not say, and consumers fall back to estimating speed
	// from the gaps between requests.
	DecodeMS int64 `json:"decodeMs,omitempty"`
	// GitBranch is the git branch the source log itself recorded for this
	// request: Claude Code writes a top-level `gitBranch` on a transcript line,
	// Codex writes `session_meta.payload.git.branch` once per rollout. It is
	// evidence carried by the record, never a read of the working tree or of
	// the current session's HEAD; the branch a log did not state stays "" and
	// readers report it as unknown rather than dropping the request.
	GitBranch string `json:"gitBranch,omitempty"`
}

UsageEvent is one model request's usage, the single source of truth.

Jump to

Keyboard shortcuts

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