@latten/adapter-gemini
v0.1.0
Published
Adapter: read Gemini CLI local session records (~/.gemini/tmp/*/chats/*.jsonl|*.json, logs.json). Parses real per-turn token counts when the files carry them (newer CLIs) and honest message counts when they don't — fidelity labeled on every result, number
Maintainers
Readme
@latten/adapter-gemini
An adapter that refuses to guess.
Gemini CLI keeps local records of your sessions in two generations. Newer CLIs
write chats/session-*.jsonl whose turns carry real token counts — input,
output, cached, thoughts, tool — and this adapter parses them
(fidelity: 'tokens-only'), splitting the cached portion out of input so cache
misses are visible. Older CLIs wrote logs.json and chats/session-*.json
with messages only — for those it reports exactly that: sessions, message
counts, timestamps, labeled fidelity: 'messages-only'.
What it never does is estimate. Every result tells you which of the two it is; a number you can't observe is a number you shouldn't report.
Install
npm install @latten/adapter-geminiUsage
Three lines to your last 24 hours:
import { readGeminiChats } from '@latten/adapter-gemini'
const chats = await readGeminiChats({ sinceMs: Date.now() - 86_400_000 })
chats.forEach((c) => console.log(c.sessionId, c.fidelity, c.tokens ?? `${c.messages} messages`))Every chat comes back at the fidelity its file supports: tokens-only (real
per-turn counts, per model) or messages-only (honest counts, nothing
invented). readGeminiLogs() does the same for the older logs.json records.
Need control? findGeminiChats() / parseGeminiChat() are the pieces the
one-liner is made of — bring your own file list or parse a single string.
npx @latten/glow uses the same honest read to show Gemini alongside Claude
Code and Codex in one usage view.
What it reads — and what it deliberately doesn't
Reads: session ids, message ids, message types, timestamps, models, and token
counts. Never reads: message text, thought text, or tool arguments. The
message, content, displayContent, thoughts, and toolCalls payloads
are not accessed, not hashed, not counted by size — they simply never enter the
model. The test suite asserts it: serialize any parsed result and the raw text
is provably absent.
Types and counts, never values — the same contract as every Latten package.
Part of the Latten session model
@latten/adapter-claude-code and @latten/adapter-codex parse full
token-level sessions for their agents. One session model, every agent your
team runs — each reported at the fidelity its files actually support.
You moved fast with AI. Latten helps you stay in control of it. See what your AI costs — and where your data goes: Latten turns the AI calls across your company into one live graph — cost, reach, and PII exposure, attributed and observed from real traffic. One prompt to your coding agent, a PR you review, live in minutes. latten.io
