Chimera Runtime Configuration: Inputs, Generation, and Loading
This page describes how Chimera prepares the configuration used by its core. At
startup and during hot reload, the core uses a generated runtime file rather
than reading profiles.yaml directly. The backend assembles the runtime
configuration in memory, writes it to disk, and provides it to the core through
startup arguments or the Clash API.
- Upstream alignment: Needs assessment
- Local maturity: In development
1. Inputs and Initialization
The runtime configuration draws on four kinds of input:
- Application settings —
chimera-config.yaml, represented byIVergeand loaded throughbackend/tauri/src/config/chimera/mod.rs→IVerge::new(). These settings control field filtering, port strategy, TUN behavior, and system-proxy behavior. - Clash Guard overrides —
clash-guard-overrides.yaml, represented byIClashTempand loaded throughbackend/tauri/src/config/clash/mod.rs→IClashTemp::new(). These values override selected fields such asmode,mixed-port,external-controller, andsecret. - Profile metadata —
profiles.yaml, represented byProfilesand loaded throughbackend/tauri/src/config/profile/profiles.rs→Profiles::new(). It records the active profile (current) and the profile list (items). - Profile content —
app_config_dir/profiles/*.yaml, read throughProfiles::current_mappings(). These files contain configuration such as proxies, rules, DNS, and TUN settings.
Startup initialization
backend/tauri/src/utils/init/mod.rs → init_config() creates the following
files when they are missing:
clash-guard-overrides.yaml, usingIClashTemp::template()chimera-config.yaml, usingIVerge::template()profiles.yaml, with an empty or default configuration
backend/tauri/src/config/core.rs → Config::global() initializes
Profiles::new(), IVerge::new(), IClashTemp::new(), and IRuntime::new().
IRuntime holds the in-memory runtime configuration; its config field is an
Option<Mapping>.
2. Runtime Configuration Generation
The documented entry point is Config::generate() in
backend/tauri/src/config/core.rs:
flowchart TD A["Start Config::generate"] --> B["Call enhance::enhance"] B --> C["Read YAML(s) of current profile"] C --> D["merge_profiles: merge configs"] D --> E["(Optional) whitelist-based field filtering"] E --> F["Override key fields (HANDLE_FIELDS)"] F --> G["Write into in-memory runtime config"] G --> H["Write out clash config YAML"] H --> I["Load at startup or hot-reload via PUT /configs"]
enhance::enhance() in backend/tauri/src/enhance/mod.rs performs these steps:
- Loads Clash Guard settings from
Config::clash().latest().0.clone(). - Reads feature settings from
IVerge, includingenable_clash_fields. - Loads the active profile content through
Profiles::current_mappings(). This iterates overcurrent, reads eachprofiles/<file>.yaml, and converts it to aMapping. - Calls
process_chain(...)for profile-chain scripts. In the implementation described here, this is a placeholder and returns the original configuration unchanged. - Calls
merge_profiles(...)to combine profile configurations. The first configuration is merged in full withextend; later configurations append only theirproxiesto the existingproxieslist. - Optionally filters fields through
use_whitelist_fields_filter(...). Whenenable_clash_fields = true, only keys in the valid and default field sets are retained. - Copies the fields in
HANDLE_FIELDSfromIClashTempinto the final configuration so the client centrally controls these values.
HANDLE_FIELDS, defined in backend/tauri/src/enhance/field.rs, contains:
modeportsocks-portmixed-portallow-lanlog-levelipv6secretexternal-controller
If a profile also defines one of these fields, the corresponding value from
clash-guard-overrides.yaml takes precedence.
3. Runtime File and Core Loading
Config::generate_file(ConfigType::Run) in backend/tauri/src/config/core.rs
writes the runtime output to app_config_dir()/clash-config.yaml. In Check
mode, it writes to temp_dir()/clash-config-check.yaml. If generation fails,
Config::init_config() falls back to writing IClashTemp directly as the
runtime configuration.
At startup
CoreManager::run_core() → Instance::try_new() in
backend/tauri/src/core/clash/core.rs calls
Config::generate_file(ConfigType::Run) and passes the resulting path to the
core through CoreInstanceBuilder.config_path(config_path). The core then reads
clash-config.yaml at startup.
During hot reload
CoreManager::update_config() follows this sequence:
Config::generate().await?rebuilds the in-memory configuration.check_config().await?validates it using the check file.generate_file(Run)rewritesclash-config.yaml.- The client sends
PUT /configswith{ "path": "<absolute path>" }to ask the core to reload it.
Relevant code is in backend/tauri/src/core/clash/core.rs → update_config()
and backend/tauri/src/core/clash/api.rs → put_configs(...).
4. Operations That Trigger a Rebuild
Changing the active profile selection
The frontend calls commands.patchProfilesConfig, which reaches
patch_profiles_config(...) in the backend. The backend applies a draft with
Config::profiles().draft().apply(...), calls CoreManager::update_config(),
then saves the profile state with Config::profiles().apply() and save_file()
on success. On failure, it calls discard() to roll back.
Changing selected application settings
The frontend calls commands.patchVergeConfig, which reaches
feat::patch_verge(...). It first writes an IVerge draft. Depending on the
field, for example enable_tun_mode, the change may regenerate configuration
and restart the core through Config::generate() + run_core(), or hot-update
it through update_core_config().
Importing the first profile
After import_profile(...) succeeds, if no profile is active, Chimera sets
ProfilesBuilder.current = [new_uid] and reuses patch_profiles_config(...) to
trigger an update.
5. Runtime Details and Limitations
profiles.yamlstores profile metadata and thecurrentpointer; it is not the final configuration consumed by the core.- Profile content files are not passed to the core verbatim. They become the runtime configuration after merging, filtering, and Clash Guard overrides.
prepare_external_controller_port()checks port availability according to policy and changes theexternal-controllerport when necessary.verge_mixed_portis primarily used by system-proxy logic. It is not written directly to the runtime YAML’smixed-port. System-proxy logic usesverge_mixed_portfirst, then falls back toConfig::clash().get_mixed_port().get_runtime_yaml()returns the in-memoryIRuntime.config. It is usually consistent with the recently writtenclash-config.yaml, but it does not reread the file on each call.
The implementation limitations recorded here are:
- Profile-chain script execution is a placeholder;
process_chain(...)does not yet rewrite the configuration. - Global chain processing remains commented out; only the scoped chain framework is present.
- The
patch_clash_configIPC is stilltodo!(), so the frontend will fail if it uses that IPC path. - Editing a profile file directly does not automatically trigger hot reload.
save_profile_file(...)writes the file but does not callupdate_config().
6. Troubleshooting
If the core appears to be using the wrong configuration, check these items in order:
- Active profile: verify
currentinprofiles.yaml. - Profile content: inspect the relevant file under
app_config_dir/profiles/. - Clash Guard overrides: check whether fields in
HANDLE_FIELDSfromclash-guard-overrides.yamlreplace the values you expected. - Generated configuration: inspect
clash-config.yaml, or callget_runtime_yaml()to view the in-memory configuration. - Reload or restart: confirm that
patch_profiles_config,patch_verge_config, orrestart_sidecarran, and check the logs for the result ofPUT /configs. - Port problems: check whether the port strategy changed
external-controller.