Add coverage and fidelity metadata to TurnRecord (#41)#76
Merged
willwashburn merged 2 commits intomainfrom Apr 25, 2026
Merged
Conversation
First cut at issue #41. Introduces explicit machine-readable metadata so commands can distinguish "missing", "zero", "aggregate-only", and "partial" usage data instead of silently treating all four as "0". What landed: - New `Fidelity` shape on `TurnRecord` with `granularity` (per-turn / per-message / per-session-aggregate / cost-only), per-field `coverage` flags (input/output/reasoning/cacheRead/ cacheCreate/toolCalls/toolResultEvents/sessionRelationships/ rawContent), and a derived `class` (full / usage-only / aggregate-only / cost-only / partial). Coverage is strictly about *availability*: `hasOutputTokens: false` means "we don't know," not "0 output tokens." - `EMPTY_COVERAGE`, `classifyFidelity`, and `makeFidelity` helpers in `@relayburn/reader`. - The Claude parser now populates fidelity on every turn; usage coverage flags reflect which fields the upstream `usage` block actually carried. - `summarizeFidelity(turns)` and `hasMinimumFidelity(...)` in `@relayburn/analyze` for command-level aggregation and gating. - `burn summary` prints a fidelity notice when any turn is below full fidelity, and `burn summary --json` now emits a structured payload including a `fidelity` block with per-class / per-granularity counts and per-field `missingCoverage` totals. What's deferred to follow-up PRs: - Codex and OpenCode parsers (they still emit no fidelity field; consumers treat absence as best-effort full). - `burn compare`, `burn waste`, `burn limits`, `burn plans` behavior gating on fidelity class. - Mux / Crush collector schemas adopting the shared shape. Schema: `TurnRecord.fidelity` is optional; older ledgers without the field continue to round-trip unchanged. No on-disk `v` bump needed. Refs #41 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 25, 2026
…a-41 # Conflicts: # packages/analyze/CHANGELOG.md # packages/analyze/src/index.ts # packages/reader/CHANGELOG.md
| ### Added | ||
|
|
||
| - **`burn mcp-server`** — stdio MCP (Model Context Protocol) server that lets a running agent self-query its own cost and quota state mid-session. Registers `burn__sessionCost` and `burn__currentBlock`. Read-only. Pair with `buildMcpConfig({sessionId})` from `@relayburn/mcp` to inject the server into a spawned `claude --mcp-config <…>` session. (#26) | ||
| - **`burn summary --json` and fidelity counts** ([#41](https://github.com/AgentWorkforce/burn/issues/41) — first cut). The default summary now prints a one-line `fidelity:` notice whenever any turn is below full or unsupported, with counts by class. `--json` emits a structured payload with `ingest`, `turns`, `totalCost`, `byModel`, and a `fidelity` block (totals by class + granularity, plus per-field `missingCoverage` counts) so programmatic consumers can distinguish numeric zero from "we don't know." Suppressed in the all-full common case to avoid noise. |
Contributor
There was a problem hiding this comment.
🟡 CLI changelog entry added to already-released [0.13.1] instead of [Unreleased]
The new burn summary --json fidelity-counts entry is added under ## [0.13.1] - 2026-04-25, which is an already-published version. Per AGENTS.md: "Curate [Unreleased] in the relevant per-package packages/*/CHANGELOG.md as you land PRs." The reader and analyze packages correctly add their entries under [Unreleased], but the CLI package does not. This will cause the publish workflow to miss this entry during the next release promotion (it promotes the [Unreleased] block, which is empty for CLI), and falsely attributes unreleased work to v0.13.1.
Prompt for agents
The new changelog bullet for 'burn summary --json and fidelity counts' is placed under the [0.13.1] section (line 15), which is an already-released version. It should be moved under the [Unreleased] section (after line 8) to match the pattern used by packages/reader/CHANGELOG.md and packages/analyze/CHANGELOG.md. Specifically, move line 15 content to between line 8 and the blank line before [0.13.1], adding the appropriate ### Added subsection header under [Unreleased].
Was this helpful? React with 👍 or 👎 to provide feedback.
This was referenced Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #41 — first cut at coverage and fidelity metadata.
Summary
Introduce explicit machine-readable metadata so commands can distinguish "missing", "zero", "aggregate-only", and "partial" usage data instead of silently treating all four as
0.What landed
TurnRecord.fidelity(optional) with three pieces:granularity:per-turn|per-message|per-session-aggregate|cost-onlycoverage: per-field availability flags (hasInputTokens,hasOutputTokens,hasReasoningTokens,hasCacheReadTokens,hasCacheCreateTokens,hasToolCalls,hasToolResultEvents,hasSessionRelationships,hasRawContent)class: derivedfull|usage-only|aggregate-only|cost-only|partialhasOutputTokens: falsemeans "we don't know," not "0 output tokens." Numeric fields onUsagecarry0when the source actually reports zero or doesn't report the field — the matching coverage flag is the only honest way to tell those apart.EMPTY_COVERAGE,classifyFidelity, andmakeFidelityhelpers in@relayburn/reader.usageblock actually carried (so a turn with nocache_creationreportshasCacheCreateTokens: false).summarizeFidelity(turns)andhasMinimumFidelity(...)in@relayburn/analyzefor command-level aggregation and gating.burn summaryprints a one-line fidelity notice whenever any turn is below full or unsupported.burn summary --jsonnow emits a structured payload (ingest,turns,totalCost,byModel,fidelity) with per-class / per-granularity counts and per-fieldmissingCoveragetotals — programmatic consumers can finally distinguish numeric zero from "we don't know."Deferred to follow-up PRs
fidelity; consumers treat absence as best-effort full for backward compat).burn compare,burn waste,burn limits,burn plansbehavior gating on fidelity class — the helpers (hasMinimumFidelity,summarizeFidelity) are now in place; wiring them into each command is the natural follow-up.Schema
TurnRecord.fidelityis optional. Older ledger entries without the field round-trip unchanged. Novbump needed.Test plan
pnpm run test:ts— 356 tests pass (15 new).fidelity.test.tsin both reader and analyze coversclassifyFidelity,makeFidelity, the unknown-bucket counting, andhasMinimumFidelityordering.missing-output-tokens.jsonlfixture) — verifyingusage.output === 0whilecoverage.hasOutputTokens === falseandclass === 'partial'.🤖 Generated with Claude Code