Skip to content
Open
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
76 changes: 37 additions & 39 deletions src/analyzers/codex_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,45 +392,43 @@ pub(crate) fn parse_codex_cli_jsonl_file(
session_name: effective_name,
});
}
"assistant" => {
// Token usage is now emitted immediately when processing token_count
// events. We still track assistant messages without additional stats
// to avoid double-counting when Codex emits separate reasoning/tool
// outputs.
if !saw_token_usage {
let model_state = session_model.clone().unwrap_or_else(|| {
let fallback = SessionModel::inferred(
DEFAULT_FALLBACK_MODEL.to_string(),
);
warn_once(format!(
"WARNING: session {file_path_str} missing model metadata; using fallback model {} for cost estimation.",
fallback.name
));
session_model = Some(fallback.clone());
fallback
});

entries.push(ConversationMessage {
application: Application::CodexCli,
model: Some(model_state.name.clone()),
global_hash: hash_text(&format!(
"{}_{}_assistant_{}",
file_path_str,
wrapper.timestamp.to_rfc3339(),
entries.len()
)),
local_hash: None,
conversation_hash: hash_text(&file_path_str),
date: wrapper.timestamp,
project_hash: "".to_string(),
stats: Stats::default(),
role: MessageRole::Assistant,
uuid: None,
session_name: session_name
.clone()
.or_else(|| fallback_session_name.clone()),
});
}
// Token usage is now emitted immediately when processing token_count
// events. We still track assistant messages without additional stats
// to avoid double-counting when Codex emits separate reasoning/tool
// outputs.
"assistant" if !saw_token_usage => {
let model_state = session_model.clone().unwrap_or_else(|| {
let fallback = SessionModel::inferred(
DEFAULT_FALLBACK_MODEL.to_string(),
);
warn_once(format!(
"WARNING: session {file_path_str} missing model metadata; using fallback model {} for cost estimation.",
fallback.name
));
session_model = Some(fallback.clone());
fallback
});

entries.push(ConversationMessage {
application: Application::CodexCli,
model: Some(model_state.name.clone()),
global_hash: hash_text(&format!(
"{}_{}_assistant_{}",
file_path_str,
wrapper.timestamp.to_rfc3339(),
entries.len()
)),
local_hash: None,
conversation_hash: hash_text(&file_path_str),
date: wrapper.timestamp,
project_hash: "".to_string(),
stats: Stats::default(),
role: MessageRole::Assistant,
uuid: None,
session_name: session_name
.clone()
.or_else(|| fallback_session_name.clone()),
});
}
_ => {}
}
Expand Down
13 changes: 6 additions & 7 deletions src/analyzers/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,14 @@ fn count_tokens(text: &str) -> u64 {
// Recursively extract all text content from a nested JSON structure
fn extract_text_from_value(value: &simd_json::OwnedValue, accumulated_text: &mut String) {
match value {
simd_json::OwnedValue::String(s) => {
// Only accumulate if it's a "text" field value, not metadata like URIs
// Only accumulate if it's a "text" field value, not metadata like URIs
simd_json::OwnedValue::String(s)
if !s.starts_with("vscode-")
&& !s.starts_with("file://")
&& !s.starts_with("ssh-remote")
{
accumulated_text.push_str(s);
accumulated_text.push(' ');
}
&& !s.starts_with("ssh-remote") =>
{
accumulated_text.push_str(s);
accumulated_text.push(' ');
}
simd_json::OwnedValue::Object(obj) => {
// Look for "text" fields specifically
Expand Down
Loading