Implement automated content-type detection for token estimation#78
Merged
Implement automated content-type detection for token estimation#78
Conversation
…stimation and dynamic model pricing calculations.
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.
PR Auto Describe
Summary
The PR refines cost reporting, introduces dynamic LLM pricing, enhances token‑estimation precision, and tightens session‑ending validation. It now prefixes all USD amounts, uses an average model price for defaults, detects content hints per tool, and guards against archiving sessions under incorrect IDs.
Key Changes
ModelPricing&get_pricing_for_modelreplace hard‑coded defaults;get_input_costnow pulls the average price.detect_content_hintadded;ContentHintenum reordered/expanded; hint‑based token rates updated.build_additional_contextnow receives tool/command, uses hint detection; session‑end hook validatessessionId.Detailed Breakdown
src/cli/stats.rs
println!format strings now append “USD” and use~$for approximations.cost_savedcalculation; recomputed afterbytes_savedto avoid double‑counting.run_detail, addedcost_savedafter computingbytes_saved.~${:.3}.src/guard/config.rs
ModelPricingstruct with fields for input, output, cached, reasoning, cache_creation costs.get_pricing_for_modelreturning preset prices for Claude‑3‑7‑Sonnet, Claude‑3‑5‑Sonnet, GPT‑4o, or an average of these.get_input_costnow defaults to the average model’s input price viaget_pricing_for_model("average")._outputetc. hints in pricing logic.src/hooks/post_tool.rs
build_additional_contextsignature extended to(&tool_name, &command).detect_content_hint(tool_name, command)to pick appropriate hint.src/hooks/session_end.rs
#[allow(dead_code)]onsession_id; added guard:src/util/token_estimate.rs
ContentHintenum reordered, addedBuildLog,Mixed; removed dead code attribute.detect_content_hint(tool_name, command_or_path)determining hint based on file extension or command patterns.estimate_tokensmapping to use new hints.tests (stats.rs)
expected_price_per_mdynamically from average pricing.Notes
~$prefix for estimates.Breaking Changes
None. Existing APIs remain functional; new helper
detect_content_hintis pure utility and does not alter external behavior. The updated default pricing may change cost outputs but does not break callers.Last updated: 2026-05-06 03:21:41