codeburn/packages/core
iamtoruk 8a812abfe5 fix(codex): stop double-billing reasoning, price cache writes at the explicit rate only
Port of #1078 (plus its #1084 hardening) onto feat/core-extraction, whose
pricing seam moved out of the provider decoder.

Fix A: OpenAI bills reasoning tokens as part of output_tokens, not on top of
it. `billableOutputTokens` in models.ts is the single source of truth for the
claude+codex carve-out; the host pricing pass and cachedCallToApiCall (the
cold/warm twins) and the models/audit display sums all route through it.
codexCredits loses its `reasoningTokens` param, which added the same
double-count back on.

Fix B: the core codex decoder reads `cache_write_input_tokens` and clamps it
into the uncached input, but leaves the bucket split to the host: only a model
whose pricing source publishes a real cache-write rate
(`cacheWriteCostIsExplicit`) may move tokens into the cache-write bucket, since
buildCosts fabricates 1.25x input when a source omits one and OpenAI charges
nothing extra before gpt-5.6. The pricing cache file is versioned so a file
written by a pre-fix binary can't read that flag back as undefined.

Cache ladder: codex results cache 12 -> 13, codex parse version gains
`-codex-pricing-v1` (the bucket move does not self-heal on read), daily cache
27 -> 28.
2026-08-21 14:44:46 -07:00
..
schemas fix(core): reconcile #1074 migrations without data loss 2026-08-21 22:25:53 +03:00
scripts build(core): stop shipping sourcemaps, expose schemas, tighten the barrel 2026-08-05 03:49:47 +03:00
src fix(codex): stop double-billing reasoning, price cache writes at the explicit rate only 2026-08-21 14:44:46 -07:00
tests fix(core): cover the codex timing gate and the custom-tool transport 2026-08-21 14:04:32 -07:00
package.json feat(cli): rehome the cline-cli provider into the workspace layout 2026-08-21 13:27:57 -07:00
README.md docs(core): replace Phase 1 skeleton README; bump core to 0.9.20 for republish 2026-07-27 10:52:38 -07:00
tsconfig.build.json chore: stop emitting declaration maps 2026-07-27 15:22:15 -07:00
tsconfig.json feat(core): observation schema, contracts, fingerprints, guardrail harnesses (phase 2) 2026-07-26 10:43:21 -07:00
tsup.config.ts feat(cli): rehome the cline-cli provider into the workspace layout 2026-08-21 13:27:57 -07:00
vitest.config.ts feat(core): observation schema, contracts, fingerprints, guardrail harnesses (phase 2) 2026-07-26 10:43:21 -07:00

@codeburn/core

The pure decode/detect engine behind CodeBurn: provider session-log decoding for 36 AI coding tools, content-minimized observation envelopes, and detector contracts.

Status: 0.x. The engine is complete and battle-tested (it is the same code the CodeBurn CLI runs, proven byte-identical to the pre-extraction implementation on a frozen real-world corpus), but the public API may still change between 0.x minor versions. Pin accordingly.

What it does

  • Decode: each provider module (@codeburn/core/providers/<name>) turns that tool's raw session records into structured call data — tokens, models, timing, tool usage — with the provider's exact dedup and skip semantics.
  • Observations: toObservations maps rich decode output into a strict, content-minimized envelope: only fingerprints, enums, numbers, timestamps, dedup keys, and canonical tool names cross the boundary. Enforced by an architecture gate and per-provider content-smuggling tests.
  • Detectors: contracts for waste/optimization findings over fingerprinted data.

What it deliberately does NOT do

No file or network I/O, no environment access, no clock reads, no pricing. Hosts (the CodeBurn CLI, apps, or your own tooling) supply the records and apply their own pricing. The only runtime dependency is zod.

Usage

import { decodeQwen } from '@codeburn/core/providers/qwen'
import { toObservations } from '@codeburn/core/providers/qwen'
import { OBSERVATION_SCHEMA_VERSION } from '@codeburn/core/schema'

const { calls, diagnostics } = decodeQwen({ records, seenKeys })

Each provider is its own subpath export; see package.json#exports for the full list. JSON Schemas for the observation envelope ship under schemas/.

Part of the CodeBurn core extraction (RFC #796, tracking #809). MIT.