- conversations/pricing.py holds no table any more (MODEL_PRICES, FAMILY_FALLBACK,
FAST_MULT, HAIKU_LONG, OPENAI_*, GEMINI_*, OTHER_PRICES, LOCAL_WATTS,
ELECTRICITY_EUR_PER_KWH, EVOX2_*, PLAN_METER_AS, PLAN_FABLE_WEIGHT gone): a
facade over the provider plugins' registry, same names and signatures;
PRICE_BOOK / USD_PER_EUR / LOCAL_* derived lazily from the plugins;
book_key() replaces openai_model / gemini_model; price_call() exposed.
- plugins/seed_registry.py: effective() = the bound store's registry when it
has ever known a provider (strict plugin-only), else the default plugins
read from PLUGINS_SEED_DIR / the plugins checkout / fixtures — offline
parses, scripts and unit tests price with zero setup, no network.
- parser: each API call priced once through ProviderRegistry.price_call
(UsageMeter.price) — list cost, cache share and the EVOX2's time from the
CallCost, plan units passed apart into the meter; priceBook = price_book().
- projects/costs.py: rates + local outputWeight from provider-evox2's pricing.
- usage/service.remote_snapshots: one loop over the providers with a
usageReader, GET /usage/{vendor} on the lab and online workers, the legacy
/claude|opencode|agy/usage only on a 404 (or the lab not answering);
per-vendor merge policies keep the exact old results.
- providers.py: per-id memo of the claiming pricer and the token-table key
(fixed per registry) — the parse prices at the old speed.
- plugins/metering.py reads USD_PER_EUR at use time.
A/B: scripts/ab/pricing-dump.py --base 1e431f52 → identical (10104 lines);
scripts/ab/parse-ab.py --base 1e431f52 --chunked → 499 files × 2 modes,
0 differing; chunked == one-shot.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
4.7 KiB
Python
104 lines
4.7 KiB
Python
"""
|
|
Parse Claude Code transcripts (~/.claude/projects/<proj>/<session>.jsonl) into a
|
|
viewable conversation: a flat thread of text / thinking / tool-call / tool-result
|
|
items (tools meant to be collapsed in the UI) plus real per-turn token usage and
|
|
dollar cost taken from each assistant message's `usage` block.
|
|
|
|
Two depths, one resumable parser (``state.ParserState``):
|
|
* ``parse_conversation(path)`` — cheap rollup for the conversation
|
|
list (title, model, counts, aggregated usage/cost, per-skill usage…).
|
|
* ``parse_conversation(path, full=True)`` — plus the full message thread for
|
|
the detail view.
|
|
|
|
The package, module by module:
|
|
* ``records`` — JSONL records (``_iter_records``, ``feed_lines``), timestamps,
|
|
clipped text blocks and thread items
|
|
* ``usertext`` — what a user record's text really is (inbox, cancel, relay,
|
|
author, held, slash commands, skill prompts, image note, compact summary)
|
|
* ``tools`` — tool buckets and sub-labels, project / service / worktree /
|
|
commit evidence, lifecycle stamps and deploys
|
|
* ``errors`` — API-error turns, usage-limit resets
|
|
* ``usage`` — ``UsageMeter``: what the calls used and cost (totals, by model,
|
|
plan units, hour bins, EVOX2 energy, context, compactions, by activity)
|
|
* ``turns`` — ``TurnState``: turn-end records, the run's input queue
|
|
* ``state`` — ``ParserState`` (owns a ``UsageMeter`` and a ``TurnState``)
|
|
and ``parse_conversation``
|
|
* ``cut`` — ``find_cut_line``
|
|
|
|
Every name the single ``parse.py`` module had is importable from here, and
|
|
``__all__`` is exactly what ``from conversations.parse import *`` gave then.
|
|
"""
|
|
|
|
import datetime
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import re
|
|
|
|
from .. import bashdiff, closing_notify, codemode, commits as gitcommits, mcpresult, taskevents, written
|
|
from ..deploycmd import deploy_invocation
|
|
from ..resources import ResourceMiner
|
|
import models
|
|
|
|
from ..pricing import (
|
|
add_usage,
|
|
local_call,
|
|
norm_usage,
|
|
plan_units,
|
|
rates_for,
|
|
usage_cache_cost,
|
|
usage_cost,
|
|
usage_tokens,
|
|
zero_usage,
|
|
)
|
|
|
|
from .records import ( # noqa: F401
|
|
BIN_MINUTES, MAX_BLOCK, SEARCH_CLIP, _BIN_MS, _bin5, _block_text, _clip,
|
|
_elapsed_ms, _item, _iter_records, _ms, _search_clip, feed_lines,
|
|
)
|
|
from .usertext import ( # noqa: F401
|
|
MAX_SKILL_PROMPT, _AUTHOR_RE, _CANCEL_RE, _COMPACT_LEAD_RE,
|
|
_COMPACT_REMINDER_RE, _COMPLETED_RE, _DONE_RE, _HELD_MIN_RE, _HELD_RE,
|
|
_HELD_SECS_RE, _IMAGE_NOTE_RE, _INBOX_RE, _INTERRUPT_RE, _NO_RESPONSE_RE,
|
|
_RELAY_RE, _SKILL_BODY_RE, _SKILL_NOTE_RE, _SLASH_ARGS_RE, _SLASH_CMD_RE,
|
|
_absorbed_followup, _cancelled_text, _compact_summary_text, _held_label,
|
|
_rel_skill_path, _relayed_message, _skill_body, _slash_command,
|
|
_split_author, _unwrap_inbox,
|
|
)
|
|
from .turns import TurnState, _TURN_END_SUBTYPES, _TURN_RECORDS, _stop_feedback # noqa: F401
|
|
from .tools import ( # noqa: F401
|
|
TOOL_BUCKET_ORDER, TOOL_BUCKETS, _AGENT_ASYNC_RE, _AGENT_RESUMED_RE,
|
|
_BASH_PREFIX, _COMMIT_CMD_RE, _DEPLOY_URL_PATTERNS, _EDIT_TOOLS,
|
|
_HOMELAB_ROOT, _LIFECYCLE_PATTERNS, _LOG_ONE_RE, _MAX_GIT_ROOTS,
|
|
_MAX_WORKTREE_ADDS, _MAX_WRITTEN_DIRS, _MEMORY_RE, _PROJECT_RE,
|
|
_SERVICE_RE, _SKILL_STAGES, _TASK_STATES, _TASK_SUBJECT_MAX,
|
|
_WORKTREE_NAME_RE, _WORKTREE_NOOP_FLAGS, _WORKTREE_RE, _bash_program,
|
|
_bucket, _deploy_call, _deployed_url, _file_ext, _lifecycle_stages,
|
|
_projects_in, _services_in, _subkey, _task_subject, _worktree_events,
|
|
)
|
|
from .errors import ( # noqa: F401
|
|
_API_ERROR_FIELD, _API_ERROR_TEXT, _MONTHS, _RESETS_EPOCH_RX, _RESETS_RX,
|
|
_real_model, api_error_kind, legacy_error_turn, limit_resets_at,
|
|
)
|
|
from .usage import ( # noqa: F401
|
|
UsageMeter, EST_CHARS_PER_TOKEN, FRESH_EXPIRY_MARGIN_MS, _COST_STATE_KEYS, _DELTA_KEYS,
|
|
_cost_state_delta, _est_tokens, _sub_usage,
|
|
)
|
|
from .state import ParserState, _UUID_RE, _project_name, parse_conversation # noqa: F401
|
|
from .cut import find_cut_line # noqa: F401
|
|
|
|
# What `from conversations.parse import *` exported when this was one module
|
|
# (every public name of its namespace, imported modules included) — the
|
|
# `conversations` barrel star-imports it.
|
|
__all__ = [
|
|
"BIN_MINUTES", "EST_CHARS_PER_TOKEN", "FRESH_EXPIRY_MARGIN_MS", "MAX_BLOCK",
|
|
"MAX_SKILL_PROMPT", "ParserState", "ResourceMiner",
|
|
"SEARCH_CLIP", "TOOL_BUCKETS", "TOOL_BUCKET_ORDER", "add_usage",
|
|
"api_error_kind", "bashdiff", "closing_notify", "codemode", "datetime",
|
|
"deploy_invocation", "feed_lines", "find_cut_line", "gitcommits", "json",
|
|
"legacy_error_turn", "limit_resets_at", "local_call", "mcpresult", "models",
|
|
"norm_usage", "os", "parse_conversation", "pathlib", "plan_units",
|
|
"rates_for", "re", "taskevents", "usage_cache_cost", "usage_cost",
|
|
"usage_tokens", "written", "zero_usage",
|
|
]
|