Skip to content

Add coverage and fidelity metadata to TurnRecord (#41)#76

Merged
willwashburn merged 2 commits intomainfrom
feat/fidelity-metadata-41
Apr 25, 2026
Merged

Add coverage and fidelity metadata to TurnRecord (#41)#76
willwashburn merged 2 commits intomainfrom
feat/fidelity-metadata-41

Conversation

@willwashburn
Copy link
Copy Markdown
Member

@willwashburn willwashburn commented Apr 25, 2026

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-only
    • coverage: per-field availability flags (hasInputTokens, hasOutputTokens, hasReasoningTokens, hasCacheReadTokens, hasCacheCreateTokens, hasToolCalls, hasToolResultEvents, hasSessionRelationships, hasRawContent)
    • class: derived full | usage-only | aggregate-only | cost-only | partial
  • Coverage is strictly about availability: hasOutputTokens: false means "we don't know," not "0 output tokens." Numeric fields on Usage carry 0 when 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, and makeFidelity helpers in @relayburn/reader.
  • The Claude parser populates fidelity on every turn; usage-coverage flags reflect which fields the upstream usage block actually carried (so a turn with no cache_creation reports hasCacheCreateTokens: false).
  • summarizeFidelity(turns) and hasMinimumFidelity(...) in @relayburn/analyze for command-level aggregation and gating.
  • burn summary prints a one-line fidelity notice whenever any turn is below full or unsupported.
  • burn summary --json now emits a structured payload (ingest, turns, totalCost, byModel, fidelity) with per-class / per-granularity counts and per-field missingCoverage totals — programmatic consumers can finally distinguish numeric zero from "we don't know."

Deferred to follow-up PRs

  • Codex and OpenCode parsers (they still emit no fidelity; consumers treat absence as best-effort full for backward compat).
  • burn compare, burn waste, burn limits, burn plans behavior gating on fidelity class — the helpers (hasMinimumFidelity, summarizeFidelity) are now in place; wiring them into each command is the natural follow-up.
  • Mux / Crush collector schemas adopting the shared shape.

Schema

TurnRecord.fidelity is optional. Older ledger entries without the field round-trip unchanged. No v bump needed.

Test plan

  • pnpm run test:ts — 356 tests pass (15 new).
  • New fidelity.test.ts in both reader and analyze covers classifyFidelity, makeFidelity, the unknown-bucket counting, and hasMinimumFidelity ordering.
  • New Claude parser tests cover the full-fidelity case, the tool-call case, and the partial case (missing-output-tokens.jsonl fixture) — verifying usage.output === 0 while coverage.hasOutputTokens === false and class === 'partial'.

🤖 Generated with Claude Code


Open in Devin Review

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>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

…a-41

# Conflicts:
#	packages/analyze/CHANGELOG.md
#	packages/analyze/src/index.ts
#	packages/reader/CHANGELOG.md
@willwashburn willwashburn merged commit 642391c into main Apr 25, 2026
@willwashburn willwashburn deleted the feat/fidelity-metadata-41 branch April 25, 2026 03:55
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 6 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/cli/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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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].
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant