Class: Agent::Sessions::Readers::Pi

Inherits:
Base
  • Object
show all
Defined in:
lib/agent/sessions/readers/pi.rb

Overview

pi session files. PROVISIONAL in a way no other reader is: this machine holds nine real pi project directories and zero session files inside them (2026-08-24), so every mapping below is written against tokentelemetry's working parser of the same format (resources/tokentelemetry, backend/main.py, _scan_pi_sessions) rather than a corpus of pi's own output. That is observation of running code, not of data — one step better than the design doc's prose, one step short of every other reader's evidence. Where the two could disagree, rule 2 already decides the outcome: a shape this reader has not seen becomes an :unknown part and a warning, never an exception, and raw carries what really happened.

The format per that parser: a header record id, cwd, timestamp, then typed records — "model_change" (provider, modelId) and "message" (model, content[], usage). usage spells its keys camelCase (cacheRead, cacheWrite) and carries agent-computed cost.

Constant Summary collapse

NON_MESSAGE_TYPES =

The header and settings records are session state, not conversation — the same judgement Codex's session_meta gets. model_change is state too: the model a LATER message used is on that message.

%w[session model_change].freeze
ROLES =
{ "user" => :user, "assistant" => :assistant }.freeze

Constants inherited from Base

Base::MAX_RECORD_BYTES

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods inherited from Base

#branching?, #compactions, #each_message, #fidelity, #initialize, #messages, #partial?, #tree, #warnings

Constructor Details

This class inherits a constructor from Agent::Sessions::Readers::Base

Instance Method Details

#usageObject

Session totals, summed per message record. No dedup: nothing observed or reported suggests pi repeats one response across records the way Claude does — but nothing proves it either, so if pi totals ever read roughly double a provider's bill, this is where to look.



34
35
36
37
38
39
40
41
42
43
# File 'lib/agent/sessions/readers/pi.rb', line 34

def usage
  total = nil
  each_record do |record, _line_number|
    usage = usage_from(record)
    next unless usage

    total = total ? total + usage : usage
  end
  total
end