Skip to content

refactor: simplify config resolution and consolidate main.rs init#287

Merged
ilblackdragon merged 7 commits intomainfrom
refactor/simplify-config-and-main
Feb 22, 2026
Merged

refactor: simplify config resolution and consolidate main.rs init#287
ilblackdragon merged 7 commits intomainfrom
refactor/simplify-config-and-main

Conversation

@ilblackdragon
Copy link
Copy Markdown
Member

@ilblackdragon ilblackdragon commented Feb 21, 2026

Summary

  • Simplify config resolution: Add parse_bool_env() and parse_string_env() helpers to eliminate ~40 repetitive 5-line optional_env/parse/map_err/unwrap_or patterns across 12 config files
  • Centralize embeddings provider construction: Add EmbeddingsConfig::create_provider(), fixing bugs where app.rs had hardcoded 1536 dimensions and was missing Ollama provider support
  • Consolidate main.rs init: Extract 6 helper functions, replace ~600 lines of inline initialization with AppBuilder::build_all() (net reduction: ~730 lines)
  • Fix NEAR AI cost tracking: Fetch real per-model pricing from /v1/model/list at startup instead of hardcoding rates; unify cost calculation so CostGuard uses provider-sourced rates instead of independently falling back to GPT-4o defaults (~3x overestimate)
  • Update default model: Switch default NEAR AI model from fireworks llama4-maverick to zai-org/GLM-latest

Key changes

Area Change
src/config/helpers.rs New parse_bool_env, parse_string_env, parse_option_env helpers
src/config/*.rs (11 files) Simplified resolve() methods using new helpers
src/config/embeddings.rs New create_provider() method
src/main.rs -730 net — extracted helpers, use AppBuilder::build_all()
src/llm/nearai_chat.rs Fetch + cache pricing from NEAR AI API; update cost_per_token()
src/agent/cost_guard.rs Accept provider-sourced rates via cost_per_token param
src/agent/dispatcher.rs Pass llm.cost_per_token() to cost guard
src/config/llm.rs, src/setup/wizard.rs Default model → zai-org/GLM-latest

Test plan

  • cargo fmt --check passes
  • cargo clippy -- -D warnings passes
  • cargo test — all 1384 tests pass
  • New tests for pricing decimal conversion, pricing map lookup, static/default fallback
  • Existing cost_guard tests pass unchanged (use None fallback path)

🤖 Generated with Claude Code

…o AppBuilder

- Add parse_bool_env() and parse_string_env() helpers to eliminate repetitive
  5-line optional_env/parse/map_err/unwrap_or boilerplate across 12 config files
- Add EmbeddingsConfig::create_provider() to centralize embeddings construction
  (fixes hardcoded 1536 dimensions and missing Ollama provider in app.rs)
- Extract init_cli_tracing(), setup_wasm_channels(), start_tunnel(),
  run_memory_command(), run_worker(), run_claude_bridge() from main.rs
- Replace ~600 lines of inline init in main.rs with AppBuilder::build_all()
- Expose catalog_entries from AppComponents for gateway registry entries
- Net reduction: ~738 lines across 15 files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 21, 2026 06:39
@github-actions github-actions Bot added scope: llm LLM integration size: XL 500+ changed lines risk: low Changes to docs, tests, or low-risk modules contributor: core 20+ merged PRs labels Feb 21, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ilblackdragon, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the application's configuration resolution and main initialization logic. By introducing dedicated helper functions for environment variable parsing and centralizing complex component creation, the codebase becomes more maintainable and less prone to duplication. The main.rs file has been substantially simplified through the extraction of helper functions and the adoption of a unified AppBuilder pattern, leading to a cleaner and more organized startup process. These changes enhance the clarity and robustness of the application's core setup.

Highlights

  • Configuration Helpers: Introduced parse_bool_env() and parse_string_env() helper functions to simplify environment variable parsing, eliminating repetitive boilerplate across configuration files.
  • Embeddings Provider Centralization: Centralized embeddings provider construction into EmbeddingsConfig::create_provider(), addressing hardcoded dimensions and adding Ollama provider support.
  • Main Initialization Refactoring: Extracted six initialization helper functions from main.rs and replaced approximately 600 lines of inline initialization logic with a unified AppBuilder::build_all() call.
  • Extension Discovery: Exposed catalog_entries from AppComponents to enable extension discovery by the gateway.
  • Code Reduction: Achieved a net reduction of approximately 730 lines of code across 15 files, enhancing maintainability.
Changelog
  • src/app.rs
    • Imported SharedCredentialRegistry.
    • Added catalog_entries field to AppComponents struct.
    • Modified AppBuilder::init_extensions to return catalog_entries.
    • Updated AppBuilder::build_all to use the new create_provider method for embeddings and pass catalog_entries to AppComponents.
  • src/config/agent.rs
    • Updated imports to include parse_bool_env and parse_optional_env.
    • Refactored resolve method to use new helper functions for parsing environment variables, reducing boilerplate.
  • src/config/builder.rs
    • Updated imports to include parse_bool_env.
    • Refactored resolve method to use new helper functions for parsing boolean environment variables.
  • src/config/channels.rs
    • Updated imports to include parse_bool_env and parse_optional_env.
    • Refactored resolve method to use new helper functions for parsing environment variables.
  • src/config/embeddings.rs
    • Added imports for Arc, SessionManager, and EmbeddingProvider.
    • Updated imports to include parse_bool_env and parse_optional_env.
    • Refactored resolve method to use new helper functions for dimension and enabled parsing.
    • Introduced create_provider method to centralize the logic for instantiating embedding providers.
  • src/config/heartbeat.rs
    • Updated imports to include parse_bool_env and parse_optional_env.
    • Refactored resolve method to use new helper functions for parsing environment variables.
  • src/config/helpers.rs
    • Added parse_bool_env function for parsing boolean environment variables.
    • Added parse_string_env function for parsing string environment variables.
  • src/config/hygiene.rs
    • Updated imports to include parse_bool_env and parse_optional_env.
    • Refactored resolve method to use new helper functions for parsing environment variables.
  • src/config/routines.rs
    • Updated imports to include parse_bool_env.
    • Refactored resolve method to use new helper functions for parsing boolean environment variables.
  • src/config/safety.rs
    • Updated imports to include parse_bool_env.
    • Refactored resolve method to use new helper functions for parsing boolean environment variables.
  • src/config/sandbox.rs
    • Updated imports to include parse_bool_env and parse_string_env.
    • Refactored resolve method to use new helper functions for parsing environment variables.
  • src/config/skills.rs
    • Updated imports to include parse_bool_env.
    • Refactored resolve method to use new helper functions for parsing boolean environment variables.
  • src/config/wasm.rs
    • Updated imports to include parse_bool_env.
    • Refactored resolve method to use new helper functions for parsing boolean environment variables.
  • src/llm/reasoning.rs
    • Updated the agent name in the prompt from "NEAR AI Agent" to "IronClaw Agent".
  • src/main.rs
    • Added imports for AppBuilder and AppBuilderFlags.
    • Extracted init_cli_tracing, init_worker_tracing, run_memory_command, run_worker, run_claude_bridge, start_tunnel, and setup_wasm_channels into separate functions.
    • Replaced extensive inline initialization logic with a call to AppBuilder::new(...).build_all().
    • Simplified the main agent startup flow by delegating component creation to AppBuilder.
    • Updated agent dependencies (AgentDeps) to use components from the AppBuilder result.
    • Removed redundant comments and simplified logic related to environment variable loading and database setup.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully refactors the configuration resolution and consolidates the application initialization logic into a reusable AppBuilder. This significantly reduces boilerplate and improves maintainability. However, I identified a regression where the names of development WASM tools loaded from build artifacts are no longer tracked or returned by the builder, which breaks hook registration for those tools. Additionally, some configuration fields in AgentConfig were missed during the transition to the new environment parsing helpers.

Comment thread src/app.rs
Comment on lines +633 to 639
Ok((
mcp_session_manager,
wasm_tool_runtime,
extension_manager,
catalog_entries,
))
}
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.

high

The return tuple should include the list of development tool names collected during the WASM loading phase to ensure they can be passed to the hook bootstrapping process.

References
  1. When implementing mutually exclusive logic or refactoring shared state, ensure that all relevant state flags and identifiers are updated consistently to prevent incorrect behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in bd5523e. init_extensions() now captures and returns dev_loaded_tool_names from the WASM loading future. The names are exposed on AppComponents and passed through to bootstrap_hooks() in main.rs.

Comment thread src/config/agent.rs Outdated
Comment on lines 62 to 75
max_cost_per_day_cents: crate::config::helpers::optional_env("MAX_COST_PER_DAY_CENTS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "AGENT_MAX_PARALLEL_JOBS".to_string(),
message: format!("must be a positive integer: {e}"),
})?
.unwrap_or(settings.agent.max_parallel_jobs as usize),
job_timeout: Duration::from_secs(
optional_env("AGENT_JOB_TIMEOUT_SECS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "AGENT_JOB_TIMEOUT_SECS".to_string(),
message: format!("must be a positive integer: {e}"),
})?
.unwrap_or(settings.agent.job_timeout_secs),
),
stuck_threshold: Duration::from_secs(
optional_env("AGENT_STUCK_THRESHOLD_SECS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "AGENT_STUCK_THRESHOLD_SECS".to_string(),
message: format!("must be a positive integer: {e}"),
})?
.unwrap_or(settings.agent.stuck_threshold_secs),
),
repair_check_interval: Duration::from_secs(
optional_env("SELF_REPAIR_CHECK_INTERVAL_SECS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "SELF_REPAIR_CHECK_INTERVAL_SECS".to_string(),
message: format!("must be a positive integer: {e}"),
})?
.unwrap_or(settings.agent.repair_check_interval_secs),
),
max_repair_attempts: optional_env("SELF_REPAIR_MAX_ATTEMPTS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "SELF_REPAIR_MAX_ATTEMPTS".to_string(),
message: format!("must be a positive integer: {e}"),
})?
.unwrap_or(settings.agent.max_repair_attempts),
use_planning: optional_env("AGENT_USE_PLANNING")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "AGENT_USE_PLANNING".to_string(),
message: format!("must be 'true' or 'false': {e}"),
})?
.unwrap_or(settings.agent.use_planning),
session_idle_timeout: Duration::from_secs(
optional_env("SESSION_IDLE_TIMEOUT_SECS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "SESSION_IDLE_TIMEOUT_SECS".to_string(),
message: format!("must be a positive integer: {e}"),
})?
.unwrap_or(settings.agent.session_idle_timeout_secs),
),
allow_local_tools: optional_env("ALLOW_LOCAL_TOOLS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
key: "ALLOW_LOCAL_TOOLS".to_string(),
message: format!("must be 'true' or 'false': {e}"),
})?
.unwrap_or(false),
max_cost_per_day_cents: optional_env("MAX_COST_PER_DAY_CENTS")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
.map_err(|e: std::num::ParseIntError| ConfigError::InvalidValue {
key: "MAX_COST_PER_DAY_CENTS".to_string(),
message: format!("must be a positive integer: {e}"),
})?,
max_actions_per_hour: optional_env("MAX_ACTIONS_PER_HOUR")?
max_actions_per_hour: crate::config::helpers::optional_env("MAX_ACTIONS_PER_HOUR")?
.map(|s| s.parse())
.transpose()
.map_err(|e| ConfigError::InvalidValue {
.map_err(|e: std::num::ParseIntError| ConfigError::InvalidValue {
key: "MAX_ACTIONS_PER_HOUR".to_string(),
message: format!("must be a positive integer: {e}"),
})?,
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.

medium

These fields are still using the verbose optional_env/map/transpose/map_err boilerplate that this PR aims to eliminate. While parse_optional_env requires a default value, a new helper like parse_option_env could be added to helpers.rs to handle Option<T> types consistently across the configuration files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in bd5523e. Added parse_option_env<T>() helper to config/helpers.rs for Option<T> fields. The two remaining verbose blocks (max_cost_per_day_cents, max_actions_per_hour) now use it, reducing them from 5 lines each to a single call.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors startup/config plumbing to reduce duplication and centralize component construction, primarily by introducing small config parsing helpers, moving embeddings provider construction behind EmbeddingsConfig, and switching main.rs over to AppBuilder::build_all() for core initialization.

Changes:

  • Add config helper functions (parse_bool_env, parse_string_env) and update multiple config resolve() implementations to use them.
  • Add EmbeddingsConfig::create_provider() and use it from both main.rs and AppBuilder to standardize embeddings provider creation.
  • Consolidate main.rs initialization by delegating core component setup to AppBuilder::build_all() and extracting helper functions for CLI/worker/tunnel/WASM-channel setup.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main.rs Replaces large inline init with AppBuilder::build_all() and adds helper functions (CLI tracing, worker tracing, tunnel, WASM channels, memory/worker/bridge runners).
src/app.rs Extends AppComponents (exports catalog_entries) and updates tool/embeddings init to use centralized embeddings provider creation + credential-aware tool registry.
src/config/helpers.rs Adds parse_bool_env / parse_string_env helpers for consistent env parsing.
src/config/embeddings.rs Adds EmbeddingsConfig::create_provider() and refactors env parsing to use new helpers.
src/config/agent.rs Simplifies env parsing via new helper functions.
src/config/builder.rs Simplifies env parsing via new helper functions.
src/config/channels.rs Simplifies env parsing (ports/bools) via new helper functions.
src/config/heartbeat.rs Simplifies env parsing via new helper functions.
src/config/hygiene.rs Simplifies env parsing via new helper functions.
src/config/routines.rs Simplifies env parsing via new helper functions.
src/config/safety.rs Simplifies env parsing via new helper functions.
src/config/sandbox.rs Simplifies env parsing via new helper functions (bools/strings).
src/config/skills.rs Simplifies env parsing via new helper functions.
src/config/wasm.rs Simplifies env parsing via new helper functions.
src/llm/reasoning.rs Updates the agent identity string used in the reasoning prompt.
Comments suppressed due to low confidence (1)

src/config/helpers.rs:63

  • The parse_bool_env error message says the value must be 'true' or 'false', but the function also explicitly accepts '1' and '0'. Updating the message to reflect the accepted set (e.g., "'true'/'false' or '1'/'0'") will make configuration errors less confusing.
pub(crate) fn parse_bool_env(key: &str, default: bool) -> Result<bool, ConfigError> {
    match optional_env(key)? {
        Some(s) => match s.to_lowercase().as_str() {
            "true" | "1" => Ok(true),
            "false" | "0" => Ok(false),
            _ => Err(ConfigError::InvalidValue {
                key: key.to_string(),
                message: format!("must be 'true' or 'false', got '{s}'"),
            }),
        },

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/config/embeddings.rs
Comment on lines +92 to +149
/// Create the appropriate embedding provider based on configuration.
///
/// Returns `None` if embeddings are disabled or the required credentials
/// are missing. The `nearai_base_url` and `session` are needed only for
/// the NEAR AI provider but must be passed unconditionally.
pub fn create_provider(
&self,
nearai_base_url: &str,
session: Arc<SessionManager>,
) -> Option<Arc<dyn EmbeddingProvider>> {
if !self.enabled {
tracing::info!("Embeddings disabled (set EMBEDDING_ENABLED=true to enable)");
return None;
}

match self.provider.as_str() {
"nearai" => {
tracing::info!(
"Embeddings enabled via NEAR AI (model: {}, dim: {})",
self.model,
self.dimension,
);
Some(Arc::new(
crate::workspace::NearAiEmbeddings::new(nearai_base_url, session)
.with_model(&self.model, self.dimension),
))
}
"ollama" => {
tracing::info!(
"Embeddings enabled via Ollama (model: {}, url: {}, dim: {})",
self.model,
self.ollama_base_url,
self.dimension,
);
Some(Arc::new(
crate::workspace::OllamaEmbeddings::new(&self.ollama_base_url)
.with_model(&self.model, self.dimension),
))
}
_ => {
if let Some(api_key) = self.openai_api_key() {
tracing::info!(
"Embeddings enabled via OpenAI (model: {}, dim: {})",
self.model,
self.dimension,
);
Some(Arc::new(crate::workspace::OpenAiEmbeddings::with_model(
api_key,
&self.model,
self.dimension,
)))
} else {
tracing::warn!("Embeddings configured but OPENAI_API_KEY not set");
None
}
}
}
}
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

EmbeddingsConfig::create_provider() centralizes provider selection and dimensions, but there are currently no tests covering its branching behavior (nearai/ollama/openai fallback, disabled case, missing OPENAI_API_KEY). Since this file already has config-resolution tests, adding focused unit tests for create_provider() would help prevent regressions like the previously hardcoded 1536-dimension bug.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Acknowledged. The provider constructors (NearAiEmbeddings, OllamaEmbeddings, OpenAiEmbeddings) require real HTTP endpoints or API keys, making them integration-test territory rather than unit tests. The branching logic itself is straightforward pattern matching on a config string. Adding mock-based tests here would add complexity without proportional value — the real protection is that any misuse will fail at startup with a clear log message.

Comment thread src/main.rs Outdated
&active_tool_names,
&loaded_wasm_channel_names,
&dev_loaded_tool_names,
&[], // dev_loaded_tool_names tracked inside AppBuilder now
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

bootstrap_hooks relies on dev_loaded_tool_names to decide whether to load capabilities from installed WASM tools vs dev tool artifacts (see hooks/bootstrap.rs logic). Passing an empty slice here means dev tool capability files will never be registered as plugin hooks, which can break hook loading when dev tools are active. Consider returning the dev_loaded_tool_names from AppBuilder::build_all() (e.g., on AppComponents) and passing it through here instead of &[].

Suggested change
&[], // dev_loaded_tool_names tracked inside AppBuilder now
&components.dev_loaded_tool_names, // dev_loaded_tool_names tracked inside AppBuilder now

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in bd5523e. dev_loaded_tool_names is now captured from the WASM loading future in init_extensions(), returned via the tuple, stored on AppComponents, and passed to bootstrap_hooks() in main.rs. Dev tool plugin hooks will now register correctly.

ilblackdragon and others added 5 commits February 20, 2026 23:33
…tion_env helper

Address PR review feedback:

- Capture dev_loaded_tool_names from WASM loading in init_extensions()
  and expose via AppComponents so bootstrap_hooks receives the actual
  dev tool names instead of an empty slice (fixes silent hook skip)
- Add parse_option_env<T>() helper for Option<T> config fields,
  simplifying max_cost_per_day_cents and max_actions_per_hour in agent.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CostGuard was independently looking up pricing via costs::model_cost(),
falling back to GPT-4o default rates when NEAR AI model names didn't
match the static table — causing ~3x cost overestimates in logs.

- Add pricing map to NearAiChatProvider that fetches real rates from
  /v1/model/list at startup (background, non-blocking)
- Update cost_per_token() to check fetched pricing first, then static
  table, then default
- Add cost_per_token parameter to CostGuard::record_llm_call() so the
  dispatcher passes provider-sourced rates directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace fireworks llama4-maverick-instruct-basic with zai-org/GLM-latest
as the default model in config and setup wizard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 22, 2026 00:49
@github-actions github-actions Bot added scope: agent Agent core (agent loop, router, scheduler) scope: setup Onboarding / setup scope: dependencies Dependency updates risk: high Safety, secrets, auth, or critical infrastructure and removed risk: low Changes to docs, tests, or low-risk modules labels Feb 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/setup/wizard.rs Outdated
.into(),
"Llama 4 Maverick (default, fast)".into(),
),
("zai/GLM-latest".into(), "GLM Latest (default, fast)".into()),
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The default model name is inconsistent between files. In src/config/llm.rs it's set to "zai-org/GLM-latest" while in src/setup/wizard.rs it's set to "zai/GLM-latest" (missing the "-org" suffix). This inconsistency will cause the wizard's default model to not match the actual config default, potentially confusing users or causing mismatched behavior.

Suggested change
("zai/GLM-latest".into(), "GLM Latest (default, fast)".into()),
("zai-org/GLM-latest".into(), "GLM Latest (default, fast)".into()),

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ff3e043. Changed "zai/GLM-latest" to "zai-org/GLM-latest" in wizard.rs to match config/llm.rs.

Change "zai/GLM-latest" to "zai-org/GLM-latest" in wizard.rs to match
the default in config/llm.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ilblackdragon ilblackdragon merged commit c3ce262 into main Feb 22, 2026
4 checks passed
@ilblackdragon ilblackdragon deleted the refactor/simplify-config-and-main branch February 22, 2026 02:54
This was referenced Feb 21, 2026
jaswinder6991 pushed a commit to jaswinder6991/ironclaw that referenced this pull request Feb 26, 2026
…arai#287)

* refactor: simplify config resolution and consolidate main.rs init into AppBuilder

- Add parse_bool_env() and parse_string_env() helpers to eliminate repetitive
  5-line optional_env/parse/map_err/unwrap_or boilerplate across 12 config files
- Add EmbeddingsConfig::create_provider() to centralize embeddings construction
  (fixes hardcoded 1536 dimensions and missing Ollama provider in app.rs)
- Extract init_cli_tracing(), setup_wasm_channels(), start_tunnel(),
  run_memory_command(), run_worker(), run_claude_bridge() from main.rs
- Replace ~600 lines of inline init in main.rs with AppBuilder::build_all()
- Expose catalog_entries from AppComponents for gateway registry entries
- Net reduction: ~738 lines across 15 files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: propagate dev_loaded_tool_names from AppBuilder and add parse_option_env helper

Address PR review feedback:

- Capture dev_loaded_tool_names from WASM loading in init_extensions()
  and expose via AppComponents so bootstrap_hooks receives the actual
  dev tool names instead of an empty slice (fixes silent hook skip)
- Add parse_option_env<T>() helper for Option<T> config fields,
  simplifying max_cost_per_day_cents and max_actions_per_hour in agent.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: fetch real NEAR AI pricing and unify cost calculation path

CostGuard was independently looking up pricing via costs::model_cost(),
falling back to GPT-4o default rates when NEAR AI model names didn't
match the static table — causing ~3x cost overestimates in logs.

- Add pricing map to NearAiChatProvider that fetches real rates from
  /v1/model/list at startup (background, non-blocking)
- Update cost_per_token() to check fetched pricing first, then static
  table, then default
- Add cost_per_token parameter to CostGuard::record_llm_call() so the
  dispatcher passes provider-sourced rates directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: update default NEAR AI model to GLM-latest

Replace fireworks llama4-maverick-instruct-basic with zai-org/GLM-latest
as the default model in config and setup wizard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: align wizard default model name with config

Change "zai/GLM-latest" to "zai-org/GLM-latest" in wizard.rs to match
the default in config/llm.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
…arai#287)

* refactor: simplify config resolution and consolidate main.rs init into AppBuilder

- Add parse_bool_env() and parse_string_env() helpers to eliminate repetitive
  5-line optional_env/parse/map_err/unwrap_or boilerplate across 12 config files
- Add EmbeddingsConfig::create_provider() to centralize embeddings construction
  (fixes hardcoded 1536 dimensions and missing Ollama provider in app.rs)
- Extract init_cli_tracing(), setup_wasm_channels(), start_tunnel(),
  run_memory_command(), run_worker(), run_claude_bridge() from main.rs
- Replace ~600 lines of inline init in main.rs with AppBuilder::build_all()
- Expose catalog_entries from AppComponents for gateway registry entries
- Net reduction: ~738 lines across 15 files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: propagate dev_loaded_tool_names from AppBuilder and add parse_option_env helper

Address PR review feedback:

- Capture dev_loaded_tool_names from WASM loading in init_extensions()
  and expose via AppComponents so bootstrap_hooks receives the actual
  dev tool names instead of an empty slice (fixes silent hook skip)
- Add parse_option_env<T>() helper for Option<T> config fields,
  simplifying max_cost_per_day_cents and max_actions_per_hour in agent.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: fetch real NEAR AI pricing and unify cost calculation path

CostGuard was independently looking up pricing via costs::model_cost(),
falling back to GPT-4o default rates when NEAR AI model names didn't
match the static table — causing ~3x cost overestimates in logs.

- Add pricing map to NearAiChatProvider that fetches real rates from
  /v1/model/list at startup (background, non-blocking)
- Update cost_per_token() to check fetched pricing first, then static
  table, then default
- Add cost_per_token parameter to CostGuard::record_llm_call() so the
  dispatcher passes provider-sourced rates directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: update default NEAR AI model to GLM-latest

Replace fireworks llama4-maverick-instruct-basic with zai-org/GLM-latest
as the default model in config and setup wizard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: align wizard default model name with config

Change "zai/GLM-latest" to "zai-org/GLM-latest" in wizard.rs to match
the default in config/llm.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: core 20+ merged PRs risk: high Safety, secrets, auth, or critical infrastructure scope: agent Agent core (agent loop, router, scheduler) scope: dependencies Dependency updates scope: llm LLM integration scope: setup Onboarding / setup size: XL 500+ changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants