Skip to content

Commit c258ffc

Browse files
klopez4212npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5
andauthored
refactor(desktop): unify EditAgentDialog styling with PersonaDialog (#1540)
Signed-off-by: npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5 <8a675edd33677aa0389f6650d467b2041fb0df4ca820eacb009babb95e3715d4@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5 <8a675edd33677aa0389f6650d467b2041fb0df4ca820eacb009babb95e3715d4@sprout-oss.stage.blox.sqprod.co>
1 parent 564ead3 commit c258ffc

13 files changed

Lines changed: 2121 additions & 426 deletions

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ const overrides = new Map([
134134
// config-parity: max_tokens_env_var + context_limit_env_var fields added to
135135
// KnownAcpRuntime (2 fields × 4 runtimes + discovery tests = ~13 lines).
136136
// Load-bearing — required for buzz-agent normalized config parity.
137-
["src-tauri/src/managed_agents/discovery.rs", 1124],
137+
// same-runtime-pin: update_time_agent_command_override + its override /
138+
// same-runtime / alias / sentinel / non-override / persona-less test matrix
139+
// (~135 lines, mostly tests) so a deliberate Custom pin survives the update
140+
// path instead of being dropped back to inherit. Load-bearing, not debt.
141+
["src-tauri/src/managed_agents/discovery.rs", 1259],
138142
// migration_tests.rs carries the harness-sync migration coverage plus the
139143
// patch_json_records owner-only writeback regression test (SECURITY.md:90
140144
// crash-safe 0o600 fallback). Load-bearing security + feature coverage, not
@@ -207,7 +211,9 @@ const overrides = new Map([
207211
// a GUI-launched DMG (the discovery_env_with_baked_floor fold).
208212
// +3: provider tri-state applied in update_managed_agent handler
209213
// (if let Some(provider_update) = input.provider { record.provider = provider_update; }).
210-
["src-tauri/src/commands/agent_models.rs", 1071],
214+
// +8: harness_override thread-through in update_managed_agent so a deliberate
215+
// Custom pin routes to update_time_agent_command_override (comment + call).
216+
["src-tauri/src/commands/agent_models.rs", 1079],
211217
// draft-persistence predicate: submit-time `loadDraft` check + inline comment
212218
// + deps-array entry in submitMessage closes the never-persisted-boundary
213219
// defect (Thufir Pass-3 finding). Load-bearing correctness fix; queued to

‎desktop/src-tauri/src/commands/agent_models.rs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,21 @@ pub async fn update_managed_agent(
860860
// that diverges from the persona. An empty/whitespace value (the
861861
// "Inherit from persona" sentinel) clears the pin back to `None`. A
862862
// name-only edit (`agent_command == None`) leaves the pin intact.
863+
//
864+
// `harness_override` threads the user's explicit intent: when they pick
865+
// a runtime/Custom command in the dialog it is a real pin even if it
866+
// maps to the persona's own runtime, so a same-runtime pick is kept
867+
// rather than dropped back to inherit (see
868+
// `update_time_agent_command_override`).
863869
if let Some(agent_command) = input.agent_command {
864870
let personas = load_personas(&app).unwrap_or_default();
865-
record.agent_command_override = crate::managed_agents::divergent_agent_command_override(
866-
record.persona_id.as_deref(),
867-
&personas,
868-
Some(&agent_command),
869-
);
871+
record.agent_command_override =
872+
crate::managed_agents::update_time_agent_command_override(
873+
record.persona_id.as_deref(),
874+
&personas,
875+
Some(&agent_command),
876+
input.harness_override,
877+
);
870878
}
871879
if let Some(agent_args) = input.agent_args {
872880
record.agent_args = agent_args;

‎desktop/src-tauri/src/managed_agents/discovery.rs‎

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,47 @@ pub fn divergent_agent_command_override(
348348
}
349349
}
350350

351+
/// Decide the `agent_command_override` to persist at AGENT UPDATE time.
352+
///
353+
/// The edit dialog sends `agent_command` as a tri-state string: the empty
354+
/// "inherit from persona" sentinel (clear the pin), or a concrete command
355+
/// (pin). Resolution:
356+
///
357+
/// - EMPTY / whitespace → the inherit sentinel: always `None` regardless of
358+
/// `harness_override`, so toggling "Inherit runtime from persona" clears the
359+
/// pin.
360+
/// - DELIBERATE OVERRIDE (`harness_override` true, persona linked): the user
361+
/// explicitly picked a runtime/Custom command in the dialog. This is a real
362+
/// pin and is preserved VERBATIM — even when the picked command maps to, or
363+
/// is byte-identical to, the persona's own runtime command. Selecting "Custom
364+
/// command" and saving e.g. `goose` for a goose persona is a deliberate act
365+
/// to freeze the harness against future persona runtime edits; dropping it
366+
/// back to inherit (as [`divergent_agent_command_override`] would) defeats
367+
/// that intent. Unlike the create-time path, there is no byte-identical
368+
/// exception here: at create the command is machine-derived from the persona,
369+
/// so equality means "no user divergence"; at update an equal command reached
370+
/// the force branch only because the user picked Custom, which IS the
371+
/// divergence.
372+
/// - NO OVERRIDE INTENT (`harness_override` false) or NO PERSONA: defer to
373+
/// [`divergent_agent_command_override`], which keeps the persona authoritative
374+
/// and treats a same-runtime restatement as inherit.
375+
pub fn update_time_agent_command_override(
376+
persona_id: Option<&str>,
377+
personas: &[crate::managed_agents::types::PersonaRecord],
378+
picked_command: Option<&str>,
379+
harness_override: bool,
380+
) -> Option<String> {
381+
let picked = picked_command
382+
.map(str::trim)
383+
.filter(|value| !value.is_empty())?;
384+
385+
if persona_id.is_some() && harness_override {
386+
return Some(picked.to_string());
387+
}
388+
389+
divergent_agent_command_override(persona_id, personas, Some(picked))
390+
}
391+
351392
/// Decide the `agent_command_override` to persist at AGENT CREATE time.
352393
///
353394
/// A persona-backed create receives its harness command from
@@ -729,8 +770,8 @@ mod tests {
729770
use super::{
730771
classify_runtime, create_time_agent_command_override, default_agent_command,
731772
divergent_agent_command_override, effective_agent_command, find_via_login_shell,
732-
managed_agent_avatar_url, normalize_agent_args, BUZZ_AGENT_AVATAR_URL,
733-
CLAUDE_CODE_AVATAR_URL, CODEX_AVATAR_URL, GOOSE_AVATAR_URL,
773+
managed_agent_avatar_url, normalize_agent_args, update_time_agent_command_override,
774+
BUZZ_AGENT_AVATAR_URL, CLAUDE_CODE_AVATAR_URL, CODEX_AVATAR_URL, GOOSE_AVATAR_URL,
734775
};
735776
use crate::managed_agents::AcpAvailabilityStatus;
736777

@@ -1120,4 +1161,98 @@ mod tests {
11201161
Some("codex-acp".to_string())
11211162
);
11221163
}
1164+
1165+
#[test]
1166+
fn update_time_override_preserves_same_runtime_pin_when_overriding() {
1167+
// The bug this fixes: the user picks "Custom command" in the edit
1168+
// dialog and saves `goose` verbatim for a goose persona. That is a
1169+
// deliberate pin (harness_override true) — it must be kept so future
1170+
// persona runtime edits stop propagating, even though it maps to the
1171+
// persona's own runtime. `divergent_agent_command_override` alone would
1172+
// wrongly drop it to `None`.
1173+
let personas = vec![persona_with_runtime("p1", Some("goose"))];
1174+
assert_eq!(
1175+
update_time_agent_command_override(Some("p1"), &personas, Some("goose"), true),
1176+
Some("goose".to_string())
1177+
);
1178+
}
1179+
1180+
#[test]
1181+
fn update_time_override_preserves_exact_persona_command_when_overriding() {
1182+
// Even when the pick is byte-identical to the persona's own command, an
1183+
// explicit Custom selection (harness_override true) is a deliberate pin
1184+
// and is preserved. This is the core divergence from the create-time
1185+
// contract: at update, equality reached the force branch only because
1186+
// the user picked Custom.
1187+
let personas = vec![persona_with_runtime("p1", Some("claude"))];
1188+
assert_eq!(
1189+
update_time_agent_command_override(
1190+
Some("p1"),
1191+
&personas,
1192+
Some("claude-agent-acp"),
1193+
true
1194+
),
1195+
Some("claude-agent-acp".to_string())
1196+
);
1197+
}
1198+
1199+
#[test]
1200+
fn update_time_override_preserves_alias_pin_when_overriding() {
1201+
// A `claude` persona with an installed `claude-code-acp` alias: picking
1202+
// it as a Custom pin is a deliberate divergence from the primary
1203+
// command and must be preserved when overriding.
1204+
let personas = vec![persona_with_runtime("p1", Some("claude"))];
1205+
assert_eq!(
1206+
update_time_agent_command_override(
1207+
Some("p1"),
1208+
&personas,
1209+
Some("claude-code-acp"),
1210+
true
1211+
),
1212+
Some("claude-code-acp".to_string())
1213+
);
1214+
}
1215+
1216+
#[test]
1217+
fn update_time_override_defers_to_divergent_when_not_overriding() {
1218+
// Without the explicit intent bit (e.g. a name-only edit that still
1219+
// echoes the command), the persona stays authoritative: a same-runtime
1220+
// command inherits, a different runtime pins.
1221+
let personas = vec![persona_with_runtime("p1", Some("goose"))];
1222+
assert_eq!(
1223+
update_time_agent_command_override(Some("p1"), &personas, Some("goose"), false),
1224+
None
1225+
);
1226+
assert_eq!(
1227+
update_time_agent_command_override(Some("p1"), &personas, Some("codex-acp"), false),
1228+
Some("codex-acp".to_string())
1229+
);
1230+
}
1231+
1232+
#[test]
1233+
fn update_time_override_clears_pin_for_inherit_sentinel() {
1234+
// The empty "Inherit from persona" sentinel always clears the pin,
1235+
// regardless of the override flag.
1236+
let personas = vec![persona_with_runtime("p1", Some("goose"))];
1237+
assert_eq!(
1238+
update_time_agent_command_override(Some("p1"), &personas, Some(" "), true),
1239+
None
1240+
);
1241+
assert_eq!(
1242+
update_time_agent_command_override(Some("p1"), &personas, None, true),
1243+
None
1244+
);
1245+
}
1246+
1247+
#[test]
1248+
fn update_time_override_preserves_pin_for_persona_less_agent() {
1249+
// A persona-less agent has no runtime to inherit, so any picked command
1250+
// is a real pin — preserved even without the override flag (mirrors the
1251+
// create-time persona-less contract).
1252+
let personas = vec![persona_with_runtime("p1", Some("goose"))];
1253+
assert_eq!(
1254+
update_time_agent_command_override(None, &personas, Some("codex-acp"), false),
1255+
Some("codex-acp".to_string())
1256+
);
1257+
}
11231258
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ pub struct UpdateManagedAgentRequest {
503503
pub acp_command: Option<String>,
504504
#[serde(default)]
505505
pub agent_command: Option<String>,
506+
/// True when the accompanying `agent_command` is a runtime/Custom command
507+
/// the user deliberately picked for a linked persona (i.e. the dialog is
508+
/// not inheriting). Distinguishes a real pin — including one that maps to
509+
/// the persona's own runtime — from a persona-authoritative restatement,
510+
/// so a same-runtime pick is preserved instead of being dropped back to
511+
/// inherit. Ignored when `agent_command` is absent or the inherit sentinel.
512+
#[serde(default)]
513+
pub harness_override: bool,
506514
#[serde(default)]
507515
pub agent_args: Option<Vec<String>>,
508516
#[serde(default)]

0 commit comments

Comments
 (0)