Skip to content
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
3 changes: 3 additions & 0 deletions crates/forge_config/.forge.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ frequency = "daily"
[reasoning]
enabled = true
effort = "high"

currency_symbol = "$"
currency_conversion_rate = 1.0
11 changes: 11 additions & 0 deletions crates/forge_config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ pub struct ForgeConfig {
/// selection.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub providers: Vec<ProviderEntry>,

/// Currency symbol displayed in the shell rprompt next to the session cost
/// (e.g. `"$"`, `"€"`, `"₹"`). Defaults to `"$"`.
#[serde(default)]
pub currency_symbol: String,

/// Conversion rate applied to costs before display in the shell rprompt.
/// The raw USD cost is multiplied by this value, allowing costs to be shown
/// in a local currency. Defaults to `1.0` (no conversion).
#[serde(default)]
pub currency_conversion_rate: Decimal,
}

impl ForgeConfig {
Expand Down
16 changes: 2 additions & 14 deletions crates/forge_main/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3761,17 +3761,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn(ForgeConfig) -> A + Send + Sync> UI
.map(|val| val == "1")
.unwrap_or(true); // Default to true

// Get currency symbol from environment variable, default to "$"
let currency_symbol =
std::env::var("FORGE_CURRENCY_SYMBOL").unwrap_or_else(|_| "$".to_string());

// Get conversion ratio from environment variable, default to 1.0
let conversion_ratio = std::env::var("FORGE_CURRENCY_CONVERSION_RATE")
.ok()
.and_then(|val| val.parse::<f64>().ok())
.unwrap_or(1.0);

let rprompt = ZshRPrompt::default()
let rprompt = ZshRPrompt::from_config(&self.config)
.agent(
std::env::var("_FORGE_ACTIVE_AGENT")
.ok()
Expand All @@ -3781,9 +3771,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn(ForgeConfig) -> A + Send + Sync> UI
.model(model_id)
.token_count(conversation.and_then(|conversation| conversation.token_count()))
.cost(cost)
.use_nerd_font(use_nerd_font)
.currency_symbol(currency_symbol)
.conversion_ratio(conversion_ratio);
.use_nerd_font(use_nerd_font);

Some(rprompt.to_string())
}
Expand Down
11 changes: 11 additions & 0 deletions crates/forge_main/src/zsh/rprompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt::{self, Display};

use convert_case::{Case, Casing};
use derive_setters::Setters;
use forge_config::ForgeConfig;
use forge_domain::{AgentId, ModelId, TokenCount};

use super::style::{ZshColor, ZshStyle};
Expand Down Expand Up @@ -34,6 +35,16 @@ pub struct ZshRPrompt {
/// Defaults to 1.0.
conversion_ratio: f64,
}
impl ZshRPrompt {
/// Constructs a [`ZshRPrompt`] with currency settings populated from the
/// provided [`ForgeConfig`].
pub fn from_config(config: &ForgeConfig) -> Self {
Self::default()
.currency_symbol(config.currency_symbol.clone())
.conversion_ratio(config.currency_conversion_rate.value())
}
}

impl Default for ZshRPrompt {
fn default() -> Self {
Self {
Expand Down
27 changes: 0 additions & 27 deletions forge.default.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions forge.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
}
]
},
"currency_conversion_rate": {
"description": "Conversion rate applied to costs before display in the shell rprompt.\nThe raw USD cost is multiplied by this value, allowing costs to be shown\nin a local currency. Defaults to `1.0` (no conversion).",
"$ref": "#/$defs/double",
"default": 0.0
},
"currency_symbol": {
"description": "Currency symbol displayed in the shell rprompt next to the session cost\n(e.g. `\"$\"`, `\"€\"`, `\"₹\"`). Defaults to `\"$\"`.",
"type": "string",
"default": ""
},
Comment on lines +45 to +54
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema default values are incorrect

The schema defaults (0.0 for conversion rate, "" for symbol) don't match the documented behavior in the Rust code comments which state defaults should be 1.0 and "$" respectively.

This inconsistency will confuse users and tooling that relies on the schema.

Fix: Update to match documented defaults:

"currency_conversion_rate": {
  ...
  "default": 1.0
},
"currency_symbol": {
  ...
  "default": "$"
}
Suggested change
"currency_conversion_rate": {
"description": "Conversion rate applied to costs before display in the shell rprompt.\nThe raw USD cost is multiplied by this value, allowing costs to be shown\nin a local currency. Defaults to `1.0` (no conversion).",
"$ref": "#/$defs/double",
"default": 0.0
},
"currency_symbol": {
"description": "Currency symbol displayed in the shell rprompt next to the session cost\n(e.g. `\"$\"`, `\"\"`, `\"\"`). Defaults to `\"$\"`.",
"type": "string",
"default": ""
},
"currency_conversion_rate": {
"description": "Conversion rate applied to costs before display in the shell rprompt.\nThe raw USD cost is multiplied by this value, allowing costs to be shown\nin a local currency. Defaults to `1.0` (no conversion).",
"$ref": "#/$defs/double",
"default": 1.0
},
"currency_symbol": {
"description": "Currency symbol displayed in the shell rprompt next to the session cost\n(e.g. `\"$\"`, `\"\"`, `\"\"`). Defaults to `\"$\"`.",
"type": "string",
"default": "$"
},

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

"custom_history_path": {
"description": "Path to the conversation history file; defaults to the global history\nlocation when absent.",
"type": [
Expand Down
Loading