Skip to content

Commit 786bbe5

Browse files
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7wpfleger96
andcommitted
fix(desktop): improve config bridge provider display and deep config flattening
Four display correctness fixes in the config bridge: 1. types.rs: add HarnessConstraint variant to ConfigOrigin. The locked provider branch in reader.rs was using EnvVar which caused the UI to show "From environment variable" for Alia's Anthropic provider — it is a harness constraint, not a user-set env var. 2. reader.rs: use ConfigOrigin::HarnessConstraint in the provider_locked branch so Claude Code's locked Anthropic provider displays correctly. 3. goose.rs: infer provider="databricks" when DATABRICKS_HOST is present but no explicit GOOSE_PROVIDER or active_provider is set. This surfaces the effective provider for agents on the Databricks OAuth path (Paul, Duncan) who previously showed no provider in the panel. 4. codex.rs: default provider="openai" when model_provider is absent. Codex uses OpenAI implicitly when no provider is configured; Thufir previously showed no provider. 5. schema_walker.rs: recurse two levels deep instead of one. Objects at depth 2 are now flattened as "key.subkey.subsubkey" rather than "{...}". This correctly surfaces codex [projects."<path>"] trust_level entries and [tui.model_availability_nux] model keys. Depth 3+ still shows "{...}". Co-authored-by: Will Pfleger <[email protected]> Signed-off-by: Will Pfleger <[email protected]>
1 parent 10da4f4 commit 786bbe5

6 files changed

Lines changed: 141 additions & 19 deletions

File tree

‎desktop/src-tauri/src/managed_agents/config_bridge/claude.rs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,21 @@ mod tests {
151151
#[test]
152152
fn parse_permissions_and_hooks() {
153153
let cfg = parse_settings(
154-
r#"{"permissions": {"default": "bypassPermissions"}, "hooks": {"pre-commit": {}}}"#,
154+
r#"{"permissions": {"default": "bypassPermissions"}, "hooks": {"pre-commit": {"command": "lint"}}}"#,
155155
);
156156
// permissions is an object — flattened as permissions.default
157157
assert_eq!(
158158
cfg.extra.get("permissions.default").map(|s| s.as_str()),
159159
Some("bypassPermissions")
160160
);
161-
// hooks is an object — flattened one level
161+
// hooks.pre-commit is an object — two-level flattening produces hooks.pre-commit.command
162162
assert!(
163-
cfg.extra.contains_key("hooks.pre-commit"),
164-
"hooks.pre-commit should appear in extra"
163+
cfg.extra.contains_key("hooks.pre-commit.command"),
164+
"hooks.pre-commit.command should appear in extra"
165+
);
166+
assert_eq!(
167+
cfg.extra.get("hooks.pre-commit.command").map(|s| s.as_str()),
168+
Some("lint")
165169
);
166170
}
167171

‎desktop/src-tauri/src/managed_agents/config_bridge/codex.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ fn parse_codex_config(toml_str: &str) -> Option<RuntimeFileConfig> {
5454

5555
Some(RuntimeFileConfig {
5656
model,
57-
provider: model_provider,
57+
// Default to OpenAI when no provider is configured — that is Codex's
58+
// implicit provider when model_provider is absent.
59+
provider: model_provider.or_else(|| Some("openai".to_string())),
5860
mode,
5961
thinking_effort: reasoning_effort,
6062
max_output_tokens: None,
@@ -198,10 +200,18 @@ base_url = "http://localhost:8080"
198200
fn empty_config() {
199201
let cfg = parse_codex_config("").unwrap();
200202
assert!(cfg.model.is_none());
201-
assert!(cfg.provider.is_none());
203+
// No model_provider → defaults to openai
204+
assert_eq!(cfg.provider.as_deref(), Some("openai"));
202205
assert!(cfg.mode.is_none());
203206
}
204207

208+
#[test]
209+
fn explicit_provider_wins_over_default() {
210+
let toml = r#"model_provider = "azure""#;
211+
let cfg = parse_codex_config(toml).unwrap();
212+
assert_eq!(cfg.provider.as_deref(), Some("azure"));
213+
}
214+
205215
#[test]
206216
fn invalid_toml_returns_none() {
207217
assert!(parse_codex_config("{{{{not valid").is_none());

‎desktop/src-tauri/src/managed_agents/config_bridge/goose.rs‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ fn parse_goose_config(yaml_str: &str) -> Option<RuntimeFileConfig> {
3333
.as_deref()
3434
.and_then(|ap| nested_provider_fields(&map, ap));
3535

36-
let provider = goose_provider.or_else(|| active_provider.clone());
36+
let provider = goose_provider.or_else(|| active_provider.clone()).or_else(|| {
37+
// Databricks OAuth path: DATABRICKS_HOST is set but no explicit provider.
38+
// The goose runtime uses Databricks implicitly in this case.
39+
if yaml_string(&map, "DATABRICKS_HOST").is_some()
40+
|| nested.as_ref().and_then(|n| n.host.clone()).is_some()
41+
{
42+
Some("databricks".to_string())
43+
} else {
44+
None
45+
}
46+
});
3747
let model = goose_model.or_else(|| nested.as_ref().and_then(|n| n.model.clone()));
3848
let mode = goose_mode;
3949

@@ -248,4 +258,24 @@ extensions:
248258
assert!(cfg.model.is_none());
249259
assert!(cfg.provider.is_none());
250260
}
261+
262+
#[test]
263+
fn databricks_host_without_explicit_provider_infers_databricks() {
264+
let yaml = r#"
265+
DATABRICKS_HOST: https://block-lakehouse-production.cloud.databricks.com/
266+
GOOSE_TELEMETRY_ENABLED: false
267+
"#;
268+
let cfg = parse_goose_config(yaml).unwrap();
269+
assert_eq!(cfg.provider.as_deref(), Some("databricks"));
270+
}
271+
272+
#[test]
273+
fn explicit_provider_wins_over_databricks_inference() {
274+
let yaml = r#"
275+
GOOSE_PROVIDER: anthropic
276+
DATABRICKS_HOST: https://block-lakehouse-production.cloud.databricks.com/
277+
"#;
278+
let cfg = parse_goose_config(yaml).unwrap();
279+
assert_eq!(cfg.provider.as_deref(), Some("anthropic"));
280+
}
251281
}

‎desktop/src-tauri/src/managed_agents/config_bridge/reader.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn build_provider_field(
348348
if provider_locked {
349349
return Some(NormalizedField {
350350
value: Some("Anthropic (locked)".to_string()),
351-
origin: ConfigOrigin::EnvVar,
351+
origin: ConfigOrigin::HarnessConstraint,
352352
is_writable: false,
353353
write_via: ConfigWriteMechanism::ReadOnly,
354354
overridden_value: None,
@@ -635,6 +635,7 @@ mod tests {
635635
let provider = surface.normalized.provider.unwrap();
636636
assert_eq!(provider.value.as_deref(), Some("Anthropic (locked)"));
637637
assert!(!provider.is_writable);
638+
assert_eq!(provider.origin, ConfigOrigin::HarnessConstraint);
638639
}
639640

640641
#[test]

‎desktop/src-tauri/src/managed_agents/config_bridge/schema_walker.rs‎

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ use std::collections::BTreeMap;
99
/// Value formatting:
1010
/// - Scalar values (string, number, bool) → their string representation
1111
/// - Arrays → "[N items]"
12-
/// - Objects → flatten one level deep as "key.subkey = value"; deeper nesting → "{...}".
13-
/// Subkeys are iterated from the config value directly — all subkeys the user
14-
/// has set are surfaced regardless of whether any schema defines them (intentional:
15-
/// supports arbitrary keys like env vars and custom plugin entries).
12+
/// - Objects → flatten up to two levels deep as "key.subkey" or
13+
/// "key.subkey.subsubkey = value"; deeper nesting → "{...}".
14+
/// Note: object subkeys are iterated from the config value, not filtered against the
15+
/// schema's nested properties — so all subkeys the user has set are surfaced regardless
16+
/// of whether the schema defines them (intentional: supports arbitrary keys like env vars).
1617
pub(super) fn extract_config_fields(
1718
config: &serde_json::Value,
1819
skip: &[&str],
@@ -30,10 +31,24 @@ pub(super) fn extract_config_fields(
3031
}
3132
match value {
3233
serde_json::Value::Object(obj) => {
33-
// Flatten one level: "key.subkey" = scalar_value
34+
// Flatten up to two levels: "key.subkey" and "key.subkey.subsubkey"
3435
for (subkey, subval) in obj {
3536
let flat_key = format!("{key}.{subkey}");
36-
out.insert(flat_key, format_scalar(subval));
37+
match subval {
38+
serde_json::Value::Object(subobj) => {
39+
// Second level: "key.subkey.subsubkey"
40+
for (subsubkey, subsubval) in subobj {
41+
let deep_key = format!("{flat_key}.{subsubkey}");
42+
out.insert(deep_key, format_scalar(subsubval));
43+
}
44+
}
45+
serde_json::Value::Array(arr) => {
46+
out.insert(flat_key, format!("[{} items]", arr.len()));
47+
}
48+
other => {
49+
out.insert(flat_key, format_scalar(other));
50+
}
51+
}
3752
}
3853
}
3954
serde_json::Value::Array(arr) => {
@@ -102,14 +117,72 @@ mod tests {
102117
}
103118

104119
#[test]
105-
fn nested_object_beyond_one_level_is_placeholder() {
106-
let config = json!({ "nested": { "deep": { "deeper": 1 } } });
120+
fn nested_object_at_two_levels_is_flattened() {
121+
let config = json!({ "nested": { "deep": { "value": 42 } } });
107122
let result = extract_config_fields(&config, &[]);
108-
// "nested.deep" should be "{...}" because the value is an object
123+
// Two levels deep: "nested.deep.value" = "42"
109124
assert_eq!(
110-
result.get("nested.deep").map(|s| s.as_str()),
111-
Some("{...}")
125+
result.get("nested.deep.value").map(|s| s.as_str()),
126+
Some("42")
112127
);
128+
assert!(!result.contains_key("nested.deep"));
129+
}
130+
131+
#[test]
132+
fn nested_object_beyond_two_levels_is_placeholder() {
133+
let config = json!({ "a": { "b": { "c": { "d": 1 } } } });
134+
let result = extract_config_fields(&config, &[]);
135+
// "a.b.c" is depth 3 — value is an object → "{...}"
136+
assert_eq!(result.get("a.b.c").map(|s| s.as_str()), Some("{...}"));
137+
}
138+
139+
#[test]
140+
fn projects_table_flattens_to_trust_level() {
141+
// Mirrors codex [projects."<path>"] { trust_level = "trusted" }
142+
let config = json!({
143+
"projects": {
144+
"/Users/foo/dev/buzz": { "trust_level": "trusted" },
145+
"/Users/foo/dev/other": { "trust_level": "untrusted" }
146+
}
147+
});
148+
let result = extract_config_fields(&config, &[]);
149+
assert_eq!(
150+
result
151+
.get("projects./Users/foo/dev/buzz.trust_level")
152+
.map(|s| s.as_str()),
153+
Some("trusted")
154+
);
155+
assert_eq!(
156+
result
157+
.get("projects./Users/foo/dev/other.trust_level")
158+
.map(|s| s.as_str()),
159+
Some("untrusted")
160+
);
161+
}
162+
163+
#[test]
164+
fn tui_model_availability_nux_flattens_to_model_keys() {
165+
// Mirrors codex [tui.model_availability_nux] { "gpt-5.5" = 1 }
166+
let config = json!({
167+
"tui": {
168+
"status_line": ["model-with-reasoning", "git-branch"],
169+
"model_availability_nux": { "gpt-5.5": 1 }
170+
}
171+
});
172+
let result = extract_config_fields(&config, &[]);
173+
assert_eq!(
174+
result
175+
.get("tui.status_line")
176+
.map(|s| s.as_str()),
177+
Some("[2 items]")
178+
);
179+
assert_eq!(
180+
result
181+
.get("tui.model_availability_nux.gpt-5.5")
182+
.map(|s| s.as_str()),
183+
Some("1")
184+
);
185+
assert!(!result.contains_key("tui.model_availability_nux"));
113186
}
114187

115188
#[test]

‎desktop/src-tauri/src/managed_agents/config_bridge/types.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ pub enum ConfigOrigin {
2626
/// the user picked a different model on the running instance. Runtime-only —
2727
/// never persisted; reverts to the persona model on restart/respawn.
2828
RuntimeOverride,
29+
/// Value is fixed by the harness itself — not from any user-set config or
30+
/// env var. E.g. Claude Code only supports Anthropic as a provider; the
31+
/// "locked" display is synthesized by the config bridge, not read from disk.
32+
HarnessConstraint,
2933
}
3034

3135
/// How a config field can be written back to the runtime.

0 commit comments

Comments
 (0)