Class: Agent::Sessions::Readers::Gemini
- Defined in:
- lib/agent/sessions/readers/gemini.rb
Overview
Gemini CLI chat files. Written against a real store on this machine (2026-08-24): 12 sessions, 121 records — user 20, gemini 97, info 4.
A chat is one JSON document, not JSONL, so it is read whole under a cap the way Amp's thread is. The cap is the reason this does not simply JSON.parse the file: the largest real chat here is 103 KB, but nothing in the format bounds it, and an unbounded read is the failure the base reader's chunked streaming exists to prevent.
Constant Summary collapse
- MAX_DOCUMENT_BYTES =
Amp's bound, for the same reason: a whole document must fit in memory to be parsed at all, so the only protection available is refusing to read one that is absurdly large.
32_000_000- ROLES =
"gemini" is the assistant. "info" is the CLI talking to the user ("Update successful! The new version will be used on your next run."), which is neither turn — context the operator saw, the same judgement Claude's system records get, so it arrives with include_events.
{ "user" => :user, "gemini" => :assistant }.freeze
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#header ⇒ Object
The document's own header, exposed because Layer 2's session id is the filename (the trailing hex in it is shared between sessions) while the agent's own sessionId lives in here.
-
#usage ⇒ Object
Session totals, summed per message — the counts are per API call, not a running total (verified: the real series falls as well as rises, 64138 then 8069 then 8265, which no cumulative counter does).
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
#header ⇒ Object
The document's own header, exposed because Layer 2's session id is the filename (the trailing hex in it is shared between sessions) while the agent's own sessionId lives in here.
29 30 31 |
# File 'lib/agent/sessions/readers/gemini.rb', line 29 def header document.reject { |key, _| key == "messages" } end |
#usage ⇒ Object
Session totals, summed per message — the counts are per API call, not a running total (verified: the real series falls as well as rises, 64138 then 8069 then 8265, which no cumulative counter does).
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/agent/sessions/readers/gemini.rb', line 36 def usage total = nil each_record do |record, _index| usage = usage_from(record) next unless usage total = total ? total + usage : usage end total end |