mirror of
https://github.com/mksglu/context-mode.git
synced 2026-09-19 03:27:16 +08:00
ee71b5ae56
Closes Gap #1 (P1) and Gap #2 (P2) per 16-oss-verify-gap-prd §2. GAP #1 — AgentOutput.usage cost_usd derivation Adds MODEL_PRICING_USD_PER_MTOK constant (verified against platform.claude.com/docs/en/about-claude/pricing and CloudZero 2026 pricing analysis) and derives cost_usd inside extractAgentUsage. Verified rates ($/MTok): opus-4-7: 5.00 / 25.00 / 6.25 / 0.50 (input/output/cache_write/cache_read) sonnet-4-6: 3.00 / 15.00 / 3.75 / 0.30 haiku-4-5: 1.00 / 5.00 / 1.25 / 0.10 default: sonnet-4-6 rates (safe forward-compat for new model ids) The verify-gap PRD originally cited Opus at $15/$75 — that is the prior Opus 4 rate; Opus 4.7 ships at $5/$25 (confirmed via WebSearch against CloudZero, finout.io, platform.claude.com). The constant ships with the corrected values. Resolution order: tool_input.model → input.model → response.model → "default". Unknown model id falls back to default Sonnet rates so the cost column always has SOMETHING — dashboards can flag default-priced rows as approximations. Zero-token case skips cost_usd so dashboards never show misleading "$0.00 for nothing" rows. src/session/extract.ts:1259-1313 — MODEL_PRICING constant + helpers src/session/extract.ts:1361-1376 — cost_usd append in extractAgentUsage tests/session/extract-agent-usage.test.ts +6 tracers (Sonnet 0.0105, Opus > Sonnet, Haiku < Sonnet, cache pricing, default fallback, zero-token skip) GAP #2 — git -C tilde expansion + --directory=/path equals-form Two surface-level parsing fixes in parseGitInvocation: 1. `--directory=value` equals-form now parsed. Tokenizer treats it as one token; parser slices on the literal "--directory=" prefix. 2. Leading `~` or `~/path` expanded to $HOME (or USERPROFILE on Windows, or HOMEDRIVE+HOMEPATH fallback). `~user/path` (other user) is left unchanged since the bridge does not do passwd lookups. src/session/extract.ts:474-491 — expandHomeTilde + getHomedirSafe src/session/extract.ts:541-547 — --directory= equals-form parsing src/session/extract.ts:565 — expansion applied at exit tests/session/parse-git-invocation.test.ts — 9 tracers including the real-world case (`git -C ~/Server/Mert/foo commit -m "x"` from a different cwd attributes to ~/Server/Mert/foo) Test plan: - npx vitest run tests/session/extract-agent-usage.test.ts -> 17/17 GREEN - npx vitest run tests/session/parse-git-invocation.test.ts -> 9/9 GREEN - regression sweep across extract-git-commit + cross-project-attribution -> 42/42 GREEN Platform-coordination: cost_usd field rides {...ev} envelope per PRD §5.4 stability ABI — platform auto-migration picks up the typed column when first observed.
2.9 KiB
2.9 KiB