Class: Agent::Sessions::Readers::Opencode
- Defined in:
- lib/agent/sessions/readers/opencode.rb
Overview
opencode sessions, read from the shared SQLite database the adapter already enumerates. Written against a real store on this machine (2026-08-24): 365 sessions, whose message and part rows settled every mapping below — this is the first reader whose "corpus" is a database rather than files.
A "record" here is synthetic: one message row's parsed data plus every
part row belonging to it, as => ..., "parts" => [...]. That
composite IS the raw a Message carries — rule 1 needs the parts included,
because the content lives in them, not in the message row.
Constant Summary collapse
- CONTENT_PARTS =
Conversation content. text and reasoning map 1:1; a
toolpart holds BOTH the call and its result in one row (state.input / state.output), so it becomes two Parts — the assistant's act and the tool answering — rather than flattening one of them away. %w[text reasoning tool].freeze
- STATE_PARTS =
State, not conversation, skipped in silence — the same judgement Claude's session-state records get. Observed counts in the real store: step-start 4,391, step-finish 4,380 (consumed for usage below), patch 569 (files a step touched), file 25 (attachments), agent 1, compaction 1 (surfaced through
compactions, not as a message). %w[step-start step-finish patch file agent compaction snapshot].freeze
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#usage ⇒ Object
Session totals, summed per message.
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
#usage ⇒ Object
Session totals, summed per message. No dedup is needed: one row is one API response, and the sum was verified against the store's own per-session rollup columns — 9,727,437 input / 94,266 output / 22,184,157 cache-read, exactly equal both ways on the real store.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/agent/sessions/readers/opencode.rb', line 34 def usage total = nil each_record do |record, _row_number| usage = usage_from(record) next unless usage total = total ? total + usage : usage end total end |