Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 9 additions & 354 deletions crates/tokscale-cli/src/main.rs

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions crates/tokscale-cli/src/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ pub(crate) fn load_usage_cache() -> Option<WarpUsageCache> {
serde_json::from_str(&content).ok()
}

pub fn has_usage_cache_in_home(home_dir: &Path) -> bool {
home_dir
.join(".config/tokscale/warp-cache/usage.json")
.exists()
}

pub fn run_warp_login(token: Option<String>, cookie: bool) -> Result<()> {
println!("\n {}\n", "Warp/Oz - Login".cyan());
let auth_value = match token {
Expand Down
20 changes: 4 additions & 16 deletions crates/tokscale-cli/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,10 +1792,7 @@ fn test_models_json_offline_without_pricing_cache_still_succeeds() {
assert_eq!(json["totalMessages"].as_i64().unwrap(), 3);
assert_eq!(json["entries"].as_array().unwrap().len(), 2);
let total_cost = json["totalCost"].as_f64().unwrap();
assert!(
(total_cost - 0.10).abs() < 1e-9,
"unexpected totalCost without pricing: {total_cost}"
);
assert_eq!(total_cost, 0.0);
}

#[test]
Expand All @@ -1817,10 +1814,7 @@ fn test_monthly_json_offline_without_pricing_cache_still_succeeds() {
assert_eq!(entries[0]["month"].as_str().unwrap(), "2024-06");
assert_eq!(entries[1]["month"].as_str().unwrap(), "2025-01");
let total_cost = json["totalCost"].as_f64().unwrap();
assert!(
(total_cost - 0.10).abs() < 1e-9,
"unexpected totalCost without pricing: {total_cost}"
);
assert_eq!(total_cost, 0.0);
}

#[test]
Expand All @@ -1841,10 +1835,7 @@ fn test_graph_offline_without_pricing_cache_still_succeeds() {
assert_eq!(json["summary"]["activeDays"].as_i64().unwrap(), 2);
assert_eq!(json["contributions"].as_array().unwrap().len(), 2);
let total_cost = json["summary"]["totalCost"].as_f64().unwrap();
assert!(
(total_cost - 0.10).abs() < 1e-9,
"unexpected totalCost without pricing: {total_cost}"
);
assert_eq!(total_cost, 0.0);
}

#[test]
Expand Down Expand Up @@ -1894,10 +1885,7 @@ fn test_hourly_json_offline_without_pricing_cache_still_succeeds() {
1000
);
let total_cost = json["totalCost"].as_f64().unwrap();
assert!(
(total_cost - 0.10).abs() < 1e-9,
"unexpected totalCost without pricing: {total_cost}"
);
assert_eq!(total_cost, 0.0);
}

#[test]
Expand Down
16 changes: 3 additions & 13 deletions crates/tokscale-core/src/adapters/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
{
let Some(fingerprint) = fingerprint_for_unit(&unit) else {
let (mut messages, _) = parse(&unit.path);
apply_pricing_to_messages(&mut messages, ctx.pricing);
crate::finalize_token_priced_messages(&mut messages, ctx.pricing);
return ParsedUnit {
unit,
messages: UnitMessageSource::Fresh(messages),
Expand All @@ -66,6 +66,7 @@ where
}

let (mut messages, cacheable) = parse(&unit.path);
crate::finalize_token_priced_messages(&mut messages, ctx.pricing);
let cache_entry = if messages.is_empty() || !cacheable {
None
} else {
Expand All @@ -77,7 +78,6 @@ where
None,
))
};
apply_pricing_to_messages(&mut messages, ctx.pricing);

ParsedUnit {
unit,
Expand Down Expand Up @@ -114,7 +114,7 @@ pub(crate) fn resolve_messages(
UnitMessageSource::Fresh(messages) => messages,
UnitMessageSource::CacheHit(path) => {
let mut messages = ctx.source_cache.take_messages(&path).unwrap_or_default();
apply_pricing_to_messages(&mut messages, ctx.pricing);
crate::finalize_token_priced_messages(&mut messages, ctx.pricing);
messages
}
Comment thread
makoMakoGo marked this conversation as resolved.
UnitMessageSource::CodexCacheHit { .. } | UnitMessageSource::CodexAppend(_) => {
Expand All @@ -138,13 +138,3 @@ fn fingerprint_for_unit(unit: &SourceUnit) -> Option<message_cache::SourceFinger
FingerprintPolicy::None => None,
}
}

fn apply_pricing_to_messages(
messages: &mut [UnifiedMessage],
pricing: Option<&crate::pricing::PricingService>,
) {
for message in messages {
message.refresh_derived_fields();
crate::apply_pricing_if_available(message, pricing);
}
}
12 changes: 1 addition & 11 deletions crates/tokscale-core/src/adapters/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ fn apply_headless_agent(message: &mut UnifiedMessage, is_headless: bool) {
}
}

fn apply_pricing_to_messages(
messages: &mut [UnifiedMessage],
pricing: Option<&pricing::PricingService>,
) {
for message in messages {
message.refresh_derived_fields();
crate::apply_pricing_if_available(message, pricing);
}
}

fn parse_full_log_source(
unit: SourceUnit,
pricing: Option<&pricing::PricingService>,
Expand Down Expand Up @@ -178,7 +168,7 @@ fn finalize_codex_messages(
message.set_timestamp(fallback_timestamp);
}
}
apply_pricing_to_messages(&mut messages, pricing);
crate::finalize_token_priced_messages(&mut messages, pricing);
for message in &mut messages {
apply_headless_agent(message, is_headless);
}
Expand Down
181 changes: 0 additions & 181 deletions crates/tokscale-core/src/adapters/crush.rs

This file was deleted.

44 changes: 3 additions & 41 deletions crates/tokscale-core/src/adapters/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,14 @@ pub(crate) struct CachedFileAdapter {
parse: fn(&Path) -> Vec<UnifiedMessage>,
}

#[derive(Clone, Copy)]
pub(crate) enum PricingPolicy {
ApplyAlways,
ApplyIfCostNonPositive,
Never,
}

impl PricingPolicy {
pub(crate) fn apply(
self,
message: &mut UnifiedMessage,
pricing: Option<&crate::pricing::PricingService>,
) {
match self {
PricingPolicy::ApplyAlways => crate::apply_pricing_if_available(message, pricing),
PricingPolicy::ApplyIfCostNonPositive if message.cost <= 0.0 => {
crate::apply_pricing_if_available(message, pricing);
}
PricingPolicy::ApplyIfCostNonPositive | PricingPolicy::Never => {}
}
}
}

pub(crate) struct NonCachedFileAdapter {
client: ClientId,
parse: fn(&Path) -> Vec<UnifiedMessage>,
pricing_policy: PricingPolicy,
}

impl NonCachedFileAdapter {
pub(crate) const fn new(
client: ClientId,
parse: fn(&Path) -> Vec<UnifiedMessage>,
pricing_policy: PricingPolicy,
) -> Self {
Self {
client,
parse,
pricing_policy,
}
pub(crate) const fn new(client: ClientId, parse: fn(&Path) -> Vec<UnifiedMessage>) -> Self {
Self { client, parse }
}
}

Expand All @@ -75,14 +43,11 @@ impl LocalSourceAdapter for NonCachedFileAdapter {

fn parse(&self, units: Vec<SourceUnit>, ctx: &ParseContext<'_>) -> Vec<ParsedUnit> {
let parse = self.parse;
let pricing_policy = self.pricing_policy;
units
.into_par_iter()
.map(|unit| {
let mut messages = parse(&unit.path);
for message in &mut messages {
pricing_policy.apply(message, ctx.pricing);
}
crate::finalize_token_priced_messages(&mut messages, ctx.pricing);
ParsedUnit {
unit,
messages: UnitMessageSource::Fresh(messages),
Expand Down Expand Up @@ -248,8 +213,6 @@ pub(crate) static GEMINI_ADAPTER: PolicyFileAdapter =
PolicyFileAdapter::new(ClientId::Gemini, parse_gemini_file_with_policy);
pub(crate) static GROK_ADAPTER: CachedFileAdapter =
CachedFileAdapter::new(ClientId::Grok, sessions::grok::parse_grok_updates_file);
pub(crate) static WARP_ADAPTER: CachedFileAdapter =
CachedFileAdapter::new(ClientId::Warp, sessions::warp::parse_warp_file);
pub(crate) static AMP_ADAPTER: CachedFileAdapter =
CachedFileAdapter::new(ClientId::Amp, sessions::amp::parse_amp_file);
pub(crate) static DROID_ADAPTER: CachedFileAdapter =
Expand All @@ -267,7 +230,6 @@ pub(crate) static COMMANDCODE_ADAPTER: CachedFileAdapter = CachedFileAdapter::ne
pub(crate) static ANTIGRAVITY_ADAPTER: NonCachedFileAdapter = NonCachedFileAdapter::new(
ClientId::Antigravity,
sessions::antigravity::parse_antigravity_file,
PricingPolicy::ApplyAlways,
);

#[cfg(test)]
Expand Down
Loading
Loading